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...


Need help with the parts that sayTODO in images ,This may be neededscoresheet 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;="">
_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 <>
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() <=>
}


public Set unusedCategories()
{
Set result = new HashSet<>();
Category[] values = Category.values();
for (int i = 0; i < values.length;="">
{
if (_scores[i] <>
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();="">
{
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();="">
{
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) <>
return false;
if (countDiceOf(4,dice) <>
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;="">
{
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;="">
{
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;
}

Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here