**/ 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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

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

1
/**
* 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
6 -
7
8
10
11 -
/**
12
* disable all the selectors
13
*/
public void disableselectors ()
{
// TODO -- make this code actually disable all the selectors
// this code will need to use the _selectors map that will already be created and filled
}
14
15 -
16
17
18
19
20 -
/**
* get the scoresheet being displayed
@return the scoresheet, never null
*/
21
22
*
23
24
25
// the map of the selectors, one for each category
private Map<Category, JButton> _selectors;
26
27
28
// all the individual display fields
private JTextField _onesScore;
private JTextField _twosScore;
private JTextField _threesScore;
private JTextField _foursScore;
private JTextField _fivesScore;
private JTextField _sixesScore;
29
30
31
32
33
34
35
36
37
private JTextField _upperBonusScore;
38
private JTextField _smallstraightScore;
private JTextField _largeStraightScore;
private JTextField _threeofKindScore;
private JTextField _fourofKindScore;
private JTextField _fullHouseScore;
private JTextField _yahtzeeScore;
private JTextField _chanceScore;
39
40
41
42
43
44
45
46
47
private JTextField totalScore;
48 }
mstun
Transcribed Image Text:1 /** * 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 6 - 7 8 10 11 - /** 12 * disable all the selectors 13 */ public void disableselectors () { // TODO -- make this code actually disable all the selectors // this code will need to use the _selectors map that will already be created and filled } 14 15 - 16 17 18 19 20 - /** * get the scoresheet being displayed @return the scoresheet, never null */ 21 22 * 23 24 25 // the map of the selectors, one for each category private Map<Category, JButton> _selectors; 26 27 28 // all the individual display fields private JTextField _onesScore; private JTextField _twosScore; private JTextField _threesScore; private JTextField _foursScore; private JTextField _fivesScore; private JTextField _sixesScore; 29 30 31 32 33 34 35 36 37 private JTextField _upperBonusScore; 38 private JTextField _smallstraightScore; private JTextField _largeStraightScore; private JTextField _threeofKindScore; private JTextField _fourofKindScore; private JTextField _fullHouseScore; private JTextField _yahtzeeScore; private JTextField _chanceScore; 39 40 41 42 43 44 45 46 47 private JTextField totalScore; 48 } mstun
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Concept of Threads
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education