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; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
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 Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY