Question: Use the code for Die.java and Dice.java below to complete the assignment Create 2 files named ScoreCard.java and ScoreCardTester.java. In ScoreCard.java create an attribute, onesScore

Use the code for Die.java and Dice.java below to complete the assignment Create 2 files named ScoreCard.java and ScoreCardTester.java. In ScoreCard.java create an attribute, onesScore initialized to -1, to record the score of ones rolled Create a method in scoreCard.java, 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.

Next create a method in ScoreCard.java, void scoreOnes(), that sets onesScore using the onesValue() method in Dice.java.

Use ScoreCardTester to test the scoreOnes() method

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; public Dice() { this.dice = new ArrayList(); this.numDice = 5; this.numSides = 6; } public int count() { return numDice; } public int getNumSides() { return numSides; } public void addDie(Die die) { dice.add(die); } public void rollDice() { for(int i = 0; i < dice.size(); ++i) { dice.get(i).roll(); } } public int onesValue() { int onesValue; ArrayList ones = new ArrayList(); for(int index = 0; index < numDice; ++index) { ones.add(dice.get(index).getCurrentValue()); } onesValue = Collections.frequency(ones, 1)*1; return onesValue; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!