Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

0764549634, 9780764549632

More Books

Students also viewed these Databases questions