**/ enable all the selectors that are still available in the scoresheet */ public void enableSelectors() { // TODO -- make this code actually enable or disable the selectors // this code will need to use the selectors map that will already be created and filled /** * disable all the selectors */ public void disableSelectors() { // TODO -- // this code will need to use the _selectors map that will already be created and filled } make this code actually disable all the selectors

Question

Need help with the parts that say TODO in the image, This may be needed scoresheet code below

 

package edu.vtc.cis2271.yahtzee;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Scoresheet
{

private static final int SMALL_STRAIGHT_SCORE = 30;
private static final int LARGE_STRAIGHT_SCORE = 40;
private static final int FULL_HOUSE_SCORE = 25;
private static final int YAHTZEE_SCORE = 50;
private static final int TOP_HALF_BONUS = 35;
private static final int TOP_HALF_BONUS_LEVEL = 63;

@SuppressWarnings("javadoc")
public enum Category {
Ones,Twos,Threes,Fours,Fives,Sixes,
SmallStraight,LargeStraight,ThreeOfKind,FourOfKind, FullHouse, Yahtzee,Chance
}

public Scoresheet()
{
_scores = new int[Category.values().length];
_listeners = new ArrayList<>();
for (int i = 0; i < _scores.length; i++)
_scores[i] = -1;
}

public void addScoreSheetListener(ScoreSheetListener listener)
{
_listeners.add(listener);
}

public void removeScoreSheetListener(ScoreSheetListener listener)
{
_listeners.remove(listener);
}

private void notifyListeners(Category c)
{
for (ScoreSheetListener listener : _listeners)
{
listener.updateScore(c);
}
}

public boolean isUsed(Category category)
{
return _scores[category.ordinal()] >= 0;
}

public boolean isCompleted()
{
for (int score : _scores)
{
if (score < 0)
return false;
}
return true;
}

public int getScore(Category category)
{
return _scores[category.ordinal()];
}

public int getTopBonus()
{
if (getTopScore() >= TOP_HALF_BONUS_LEVEL)
return TOP_HALF_BONUS;
else
return 0;
}

public boolean impactsTopBonus(Category category)
{
return category.ordinal() >= Category.Ones.ordinal() &&
category.ordinal() <= Category.Sixes.ordinal();
}

public Set<Category> unusedCategories()
{
Set<Category> result = new HashSet<>();
Category[] values = Category.values();
for (int i = 0; i < values.length; i++)
{
if (_scores[i] < 0)
result.add(values[i]);
}
return result;
}

public boolean useRoll(Category category,int[] dice)
{
if (_scores[category.ordinal()] >= 0)
return false;
_scores[category.ordinal()] = computeValue(category,dice);
notifyListeners(category);
return true;
}

public int computeValue(Category category,int[] dice)
{
switch (category)
{
case Ones:
return countDiceOf(1,dice);
case Twos:
return countDiceOf(2,dice)*2;
case Threes:
return countDiceOf(3,dice)*3;
case Fours:
return countDiceOf(4,dice)*4;
case Fives:
return countDiceOf(5,dice)*5;
case Sixes:
return countDiceOf(6,dice)*6;
case SmallStraight:
if (isSmallStraight(dice))
return SMALL_STRAIGHT_SCORE;
return 0;
case LargeStraight:
if (isLargeStraight(dice))
return LARGE_STRAIGHT_SCORE;
return 0;
case ThreeOfKind:
if (isThreeOfKind(dice))
return countTotalOfDice(dice);
return 0;
case FourOfKind:
if (isFourOfKind(dice))
return countTotalOfDice(dice);
return 0;
case Yahtzee:
if (isFiveOfKind(dice))
return YAHTZEE_SCORE;
return 0;
case FullHouse:
if (isFullHouse(dice))
return FULL_HOUSE_SCORE;
return 0;
case Chance:
return countTotalOfDice(dice);
}
return 0;
}

public int getTotalScore()
{
return getTopScore() + getBottomScore();
}

private int getTopScore()
{
int score = 0;
for (int i = Category.Ones.ordinal(); i <= Category.Sixes.ordinal(); i++)
{
if (_scores[i] > 0)
score += _scores[i];
}
if (score > TOP_HALF_BONUS_LEVEL)
score += TOP_HALF_BONUS;
return score;
}

private int getBottomScore()
{
int score = 0;
for (int i = Category.SmallStraight.ordinal(); i <= Category.Chance.ordinal(); i++)
{
if (_scores[i] > 0)
score += _scores[i];
}
return score;
}

private int countDiceOf(int count, int[] dice)
{

return 0;
}

private int countTotalOfDice(int[] dice)
{

return 0;
}

boolean isThreeOfKind(int[] dice)
{

return false;
}

private boolean isFourOfKind(int[] dice)
{

return false;
}

private boolean isFiveOfKind(int[] dice)
{

return false;
}

private boolean isSmallStraight(int[] dice)
{
boolean hasOne;
boolean hasTwo;
boolean hasFive;
boolean hasSix;

if (countDiceOf(3,dice) < 1)
return false;
if (countDiceOf(4,dice) < 1)
return false;
hasOne = countDiceOf(1,dice) >= 1;
hasTwo = countDiceOf(2,dice) >= 1;
hasFive = countDiceOf(5,dice) >= 1;
hasSix = countDiceOf(6,dice) >= 1;
return (hasOne && hasTwo) || (hasTwo && hasFive) || (hasFive && hasSix);
}

private boolean isLargeStraight(int[] dice)
{
int d;
boolean hasOne = countDiceOf(1,dice) == 1;
boolean hasSix = countDiceOf(6,dice) == 1;
if (hasOne == hasSix)
return false;
for (d = 2; d <= 5; d++)
{
if (countDiceOf(d,dice) != 1)
return false;
}
return true;
}

private boolean isFullHouse(int[] dice)
{
boolean hasPair = false, hasThree = false;
for (int d = 1; d <= 6; d++)
{
int count = countDiceOf(d,dice);
if (count == 2)
hasPair = true;
else if (count == 3)
hasThree = true;
else if (count > 0)
return false;
}
return hasPair && hasThree;
}

private int[] _scores;
private final List<ScoreSheetListener> _listeners;
}

**/
enable all the selectors that are still available in the scoresheet
*/
public void enableSelectors()
{
// TODO -- make this code actually enable or disable the selectors
// this code will need to use the selectors map that will already be created and filled
/**
* disable all the selectors
*/
public void disableSelectors()
{
// TODO --
// this code will need to use the _selectors map that will already be created and filled
}
make this code actually disable all the selectors
Expand
Transcribed Image Text

**/ enable all the selectors that are still available in the scoresheet */ public void enableSelectors() { // TODO -- make this code actually enable or disable the selectors // this code will need to use the selectors map that will already be created and filled /** * disable all the selectors */ public void disableSelectors() { // TODO -- // this code will need to use the _selectors map that will already be created and filled } make this code actually disable all the selectors

Expert Answer

1 Rating

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Programing Language

Java

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: Only C/C++

A: #include &lt;iostream&gt;using namespace std;// This functions returns the// Maximum no of students ...

Q: Write the SQL statements for the following User table. User_id Name City Order_date Purchase_amount ...

A: To create a table in SQL, create table command is used. Ans 1. The required query is: CREATE TABLE U...

Q: (d) create_area_dict(list2D) that takes a 2D-list containing the database as input and creates a dic...

A: def create_area_dict(database):    d={}    for i in range(len(database)):        key=database[i][0] ...

Q: Write a python program that lets the user play the game of Rock, Paper, Scissors against the compute...

A: #Rock, Paper, Scissors Game import random while True: choice=int(input("Enter your choice 1.Rock, 2...

Q: TIME CLASS (Language: C++) - Write a time class named timeClass  - Write code to demonstrate that it...

A: Program: Filename: Main.java   import java.util.*; import java.lang.*; import java.io.*;   class Mai...

Q: code is to be written in C A palindrome is a word that reads the same forward and backwards. For exa...

A: Introduction of the Program: The C program creates char type arrays that stores string and the progr...

Q: please provide some explanations to help me understand the topic.

A: Based on our rule, when multiple questions are posted, we should answer only the first one. Please r...

Q: Write an if-else statement to describe an object. Print "Balloon" if isBalloon is true and isRed is ...

A: import java.util.Scanner; public class RedBalloon {       public static void main (String [] args) {...

Q: The Code must be in Matlab

A: % Defining vectorM = [0 8 11 14 17 ; 0 1 11 14 17 ; 1 2 0 14 4 ];disp('Matrix is')disp(M) % Display ...

Q: This is the question -  In Chapter 2, you created an application named QuartsToGallonsInteractive th...

A: InputMismatchException occurs when the number entered by the user is of a different data type than t...

Q: Sentiment analysis is a very effective way to enhance and develop your business using the client fee...

A: Sentiment analysis: It process of understanding the emotions with software and that must be understa...

Q: Question 3) 3.1) From IEEE-754 32 Bit Single Precision To decimal baseConvert to formata) 1111111110...

A: Based on our rules, when multiple questions are posted, we should answer only the first question. Pl...

Q: python a) There are six quizzes with grades 0 through 10. The lowest grade will be dropped.b) The pr...

A: Actually, python is a easiest programming language. It is a dynamically typed programming language.

Q: Write bash script which takes array as an input of size 10 bind its even indexes to accept even valu...

A: The, script has given below;

Q: Write a C++ program that fills a 5 x 5 matrix of integers. The matrix must be a static matrix; its s...

A: Actually, c++ is a powerful general purpose language.

Q: Develop an assembly language program for 8085 microprocessor to count continuously in hexadecimal fr...

A: Program Plan:- The counter will be set by using register and loading it with starting number and th...

Q: Code in C# (OOP Concept) Suppose that Fruit, Apple, Orange, GoldenDelicious, and McIntosh are define...

A: What is an instance(object):- (OVERVIEW) A class defines a type of object, but it is not an object i...

Q: JAVA Please solve Question 4 Please solve Question 4 Please solve Question 4 Please solve Question 4...

A: Actually, java is a object oriented programming language it is platform independent.

Q: Sentiment analysis is a very effective way to enhance and develop your business using the client fee...

A: Here in this question context diagram for an Online Application system has to be built  that applies...

Q: I would like to separate the program below into two classes. When I tried to separate them, it didn'...

A: import java.util.*; //for scanner classimport java.io.*;  class Simple{  //method to calculate the a...

Q: Write a program to do the following operations on a Binary Search Tree (BST) considering the inputs ...

A: // Tree traversal in C++ #include &lt;iostream&gt;using namespace std; struct Node {  int data;  str...

Q: SOLVE IN C#

A: The main object of the program is to create a program that tests the 1Dimensional array of values is...

Q: Problem 5 ( Suppose that your hash function resolves collisions using open addressing with double ha...

A: The, answer has given below;

Q: Java GUI (Calculator) Program

A: // Java program to calculate // double integral value class GFG{  // Change the function according t...

Q: Write a user-defined function that adds or subtracts two polynomials of any order. Name the function...

A: The, given information is :  Name the function p=polyadd(p1,p2,operation). The first two input argum...

Q: You have to construct a string “cmpmpcmpm” from a blank string. There are two ways to construct a st...

A: Click to see the answer

Q: (Given 11/24/20 Homework #4 Due: 12/10/20) Following is a data description of a library: The library...

A: Actually, database is used to stores the data.

Q: For each concept in the left column below, select the closest matching item from the right column. N...

A: Inheritance               : 22 Foreign key              : 9 1:n relation              : 5 Sybase    ...

Q: Convert the following C++ programs into Pep/9 assembly 1) #include Using namespace std; void minimu...

A: Given: #include &lt;iostream&gt; using namespace std;  void minimum (int i1, int i2)  {          if ...

Q: O get_index(dictionary, list) takes two input arguments, a dictionary (crime_dict) and a list of str...

A: Objective: This program includes a function that takes two parameters and returns a list. The method...

Q: Q2: (Financial: Compare cost) Suppose you shop for rice in two different packages. You would like to...

A: import java.util.Scanner; public class Exercise_1{           public static void main(String[] args) ...

Q: Consider the functional dependency of relation R (A, B, C,D) F = {A→BC, B→C, A→B, AB→D} Compute clos...

A: Closure Set of F+ is: A→A, A→B,A→C, B→B, B→C,C→C, D→D, AB→A, AB→B, AB→C, AC→A, AC→B, AC→C, AD→A,AD→B...

Q: There is a legend about a magical park with N × N trees. The trees are positioned in a square grid w...

A: #include &lt;stdio.h&gt;int main(){ //number of trees int N; scanf("%d",&amp;N); //array to st...

Q: in c programming

A: #include &lt;stdio.h&gt;# define MAX_SIZE 5000 int main(void){    int N;    int num,c;    int a[MAX_...

Q: // Fix this program that works// Use welcome function that display the message in diffreent color// ...

A: Program Plan:- 1. Add the two functions welcome () and table().  2. The table function will display ...

Q: C++ Student Data Write a program that uses two structures Name and Student to store the following in...

A: Actually, given information about students: Create a nameType structure that consists of First Name...

Q: Write a C program, called msg.c, that reads messages from an input file (or stdin) and verifies whet...

A: #include &lt;stdio.h&gt;#include&lt;string.h&gt;#include&lt;stdbool.h&gt;bool foo(char msg[120]);boo...

Q: * With comments in the code

A: 1. Algoeithm Step 1 - Construct a Binary Tree with given list of Elements. Step 2 - Transform the...

Q: please use c++ to answer the following question Use inheritance and classes to represent a deck of p...

A: Actually, inheritance is a acquiring the properties from one class to another class.

Q: Qn 1: Write a C++ program to multiply 2 matrices using multi-dimensional arrays. Program should ask ...

A: Program code:     //inlcuding necessary header files #include &lt;iostream&gt; using namespace std; ...

Q: using simple loop Write a c++ program that takes 10 character type input from user. In the end, your...

A: Code: #include&lt;iostream&gt; using namespace std;   void Count(string str) { intupper = 0, lower =...