Question: Using the code for Die.java and the code andDice.java below to create the methods in DiceScoreCard 1. Create a new object, named DiceScoreCard, in a
Using the code for Die.java and the code andDice.java below to create the methods in DiceScoreCard 1. Create a new object, named DiceScoreCard, in a file named DiceScoreCard.java. Also create a tester file, DiceScoreCardTester.java
2. Within the DiceScoreCard object, create attributes to record the following scores. This may be individual variables or an array. Initialize them all to -1, to indicate empty. onesScore Result of onesValue() --->using the method in Dice.java twosScore Result of twosValue() --->using the method in Dice.java threesScore Result of threesValue() --->using the method in Dice.java foursScore Result of foursValue() --->using the method in Dice.java fivesScore Result of fivesValue() --->using the method in Dice.java sixesScore Result of sixesValue() --->using the method in Dice.java bonusScore - If the sum of onesScore through sixesScore is 63 or more, score 35. Otherwise, score 0. totalScore - Sum of all scores. Make sure to not count the -1s. Most of the scores are methods called from the YahtzeeHand object, but two of them are based on other scores in the scoresheet. 3. In the DiceScoreCard object, create the following methods:
void rollDice(boolean d1, boolean d2, boolean d3, boolean d4, boolean d5) -----Roll the dice corresponding to the true Boolean parameters. This function may also be done with an array of Booleans.
void scoreOnes() void scoreTwos() void scoreThrees() void scoreFours() void scoreFives() void scoreSixes() ----Calculate the score, and store the result in the appropriate location in the scoresheet. Also recalculate the bonus and totalScore attributes.
void displayScoresheet() ----Display all scores with labels in a neatly formatted table. Use DiceScoreCardTester.java to create an instance of DiceScoreCard and test all methods created in the DiceScoreCard object.
Example blank scoresheet (values populated from methods created in DieScoreCard.java)
Die.java import java.util.*; public class Die { private String name; private int numSides; private int currentValue; private Random generator = new Random(); public Die(){ this.numSides = 0; this.currentValue = 0; } public Die (int numSides_){ numSides = numSides_; currentValue = 0; } public int getNumSides(){ return numSides; } public int getCurrentValue(){ return currentValue; } public int roll(){ this.currentValue = generator.nextInt(numSides) + 1; return currentValue; } public String toString(){ String result=""; result += Integer.toString(currentValue); return result; } } Dice.java import java.util.*; public class Dice { private ArrayList dice; private int numDice; private int numSides; int onesValue, twosValue, threesValue, foursValue, fivesValue, sixesValue; public Dice(){ this.dice = new ArrayList(); this.numDice = 5; this.numSides = 6;
for(int i = 0; i Current Scoresheet: 1. Ones: 2. Twos: 3. Threes: 4. Fours: 5. Fives: 6. Sixes: BONUS: TOTAL: Current Scoresheet: 1. Ones: 2. Twos: 3. Threes: 4. Fours: 5. Fives: 6. Sixes: BONUS: TOTAL
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
