Need help with the parts that say TODO in images , 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 unusedCategories() { Set 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 _listeners; }

Question

Need help with the parts that say TODO in images , 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;
}

Expert Answer

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 Engineering

Data Structures

Database Management

Related Computer Engineering Q&A

Find answers to questions asked by students like you.

Q: Question 2.2 Write a function createPassword()with no return value to randomly select 8 capital lett...

A: NOTE: - Since the programming language is mentioned, the below problem is implemented in C language....

Q: Write a function called number_matrix (r,c) that takes two parameters r and c and PRINTS ON THE SCRE...

A: The matrix is  a rectangular arrangement of numbers or data.  In a matrix, the horizontal entries ar...

Q: Differentiate between scalar and superscalar processor with an aid of diagrams. Superscalar process...

A: A scaler processor is one where instructions are executed in a pipeline but only a single instructio...

Q: please help me

A: a) i) If computer A sends a frame to computer B and if the switch 1 does not have the MAC address of...

Q: Question 2: Write a program that defines a function, RoundToThousands(number), to round a number x t...

A: Step 1:- Program Approach:- 1.Declare the user-defined function that function takes one parameter. T...

Q: What is the answer for following questions?

A: 1. To find the second largest element of the given array, first of all, sort the array.Compare the p...

Q: This is a PYTHON quesion.

A: Given program is below with well commented and with output.

Q: Write a function that takes a string representing the binary representation of a number, computes th...

A: Please find the answer below :

Q: The language is C++ 3. Write a program to calculate the factorial value of the inputnumber.Use the i...

A: The C++ program is written which will be user defined input of the function. The program uses the fo...

Q: Find out key value of vertex v2 for prims algorithm if current key values of vertices v1 &amp; v2 ar...

A: Prim's algorithm is used to find the minimum spanning tree. The idea is to start at a random node an...

Q: Q. With meaningful examples of your own write down usage of all the a. File & directory commands b. ...

A: Actually, program is a executable software that runs on a computer.

Q: 1. Discuss the purpose of media and information to an individual and the society.

A: Now-a-days media became part of everyone's life and media may be printed media, television media and...

Q: Develop an algorithm and implement First-In-First-Out (FIFO) page replacement algorithm using C/C++....

A: answer  given string :- 11 13 10 14 15 12 11 19 18 16 15 17 14 16 19 21  frame size = 3 (FIFO)   ...

Q: write a program with C language

A: program approach   print the graph         get the maximum value of distribution·         assume a ...

Q: Explain the historical development of programming languages and compare Object Oriented Programming ...

A: Click to see the answer

Q: How to write a valid standard php code block?

A: Please find the answer below :

Q: 1) Express the following numbers in Binary Format (base 2): a) 10, b) 24, c) 1024

A: Division Quotient Remainder Number 10/2 5 0 0 5/2 2 1 1 2/2 1 0 2 1/2 0 1 3 (10)10 = ...

Q: Write a function that takes a number and returns the largest digit value in the number. For example,...

A: Please find the answer below :  

Q: (MATLAB) Create the following vector using a while loop: [0 -20 -40 -60 -80]

A: Please find the answer below :  

Q: write a simple c++ program that calculates the amount of money earned on an investment, based on an ...

A: Please find the answer below :  

Q: Write an ARM assembly program to check whether an N x N matrix is a magic square. A magic square is ...

A: Assembly language: It is low-level programming language Each personal system has microprocessor that...

Q: how to covert file.txt data into 2D array in java

A: how to covert file.txt data into 2D array in java Instantiate Scanner or other relevant class to re...

Q: Help please

A: Solution is in Step 2.

Q: On reaching the railway station, you find that the train you wanted to catch is just to start and th...

A: ALGORITHM   START declare 5 integers num, count_a, count_b, count_c, and count_d. initialize count_a...

Q: What is the greatest advantage of using wireless?

A: Please find the answer below :

Q: Sequential and direct access are two methods to locate data in memory. Why major devices now a days ...

A: Secondary Hard Disk Pendrive Computer Operating System Mobile Phones Tablets

Q: c. Discuss whether software development projects are more susceptible to Scope Creep than other type...

A: (c) It is essential that a functional specification is produced at the beginning, written in terms t...

Q: CPI stands for clock cycles per instruction. Speedup from pipelining = (Number of pipeline stages) /...

A: Solution is in Step 2.

Q: Use switch statement to implement this logic. Give solution in C++ Language with secreenshoot

A: switch statement in C++ It allows a variable to be tested with respect to a list of values.  Each va...

Q: 1. Why Data Bus is bidirectional? ...

A: Introduction of Bus organization and Registers: In computer architecture, a bus is a group of wires ...

Q: Given a code segment of queue implementation                  if(front == rear)          front = rea...

A: The given problem is related to data structure queue. A queue is a Linear data structure where the d...

Q: File CountLetters.java contains a program that reads a word from the user and prints the number ofoc...

A: The given code generates an ArrayIndexOutOfBoundsException when more than one word is entered as an ...

Q: Implement this program to understand use of Arrays in real world examples. A small airline has just...

A: Note: Below is the required program in java language. Program Explanation: Two functions are include...

Q: what are the possible operations that can be performed on pointers explain with the help of suitable...

A: Pointer is a variable which stores the address of another variable Thus, the pointer is address of s...

Q: How to get 8x1 by using 2  4x1 mux?

A: To make 8 x 1 MUX, we need two 4 x 1 MUX. A0,A1,A2,A3 are input lines to each 4 x 1 MUX. And S0 and ...

Q: In python: you will be building a software application that will print the most popular ice-cream fl...

A: #software application to print the most popular ice-cream flavor among kids #function to creat a dic...

Q: Audio Cds encode music at 44,000 Hz using 16-bit samples. Would it make sense to produce higher qual...

A: Actually, the given question is : Audio Cds encode music at 44,000 Hz using 16-bit samples. Would it...

Q: Consider this code snippet.                 bnez    r1, L1              ; branch to L1 if r1 != 0   ...

A: Actually, register is a used to stores the small amount of data or information.

Q: Review the program Warning.java that reads in a file of student academic credit data. Each line of t...

A: The Java program is written where it takes the input student file and add the GPA function to the gi...

Q: Write a function num digits that takes a number, and returns the count of digits in the number. For ...

A: Introduction of the Program: The Python code creates a function that takes a number as a parameter a...

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

A: As specified in the question, The BST tree takes a string as input. Structure of Binary Search Tree...

Q: a. f1(n) is Ω(f6(n)) b. f5(n) is Q(f3(n)) c. f1(n) is O(f3(n)) d. f5(n) is O(f1(n)) e. f6(n) is Ω(f4...

A: Asymptotic notation : Mathematical way of representation of time complexity.  They are use to compar...

Q: I need a python program to write the csv file with the data contains about reservation details of 50...

A: Define module csv Define list variable names with elements to be set as row names Define list data w...