Question: You are given the main tester program named DiceTester and the output produced by it. You must write the dice class definition file named Dice.java

You are given the main tester program named DiceTester and the output produced by it. You must write the dice class definition file named Dice.java which will satisfy the class definition required by DiceTester.java. Be sure to write your Dice.java in the same directory with DiceTester.java

Look at the main and see how the Dice class is constructed and what methods are called. From those observations, you can deduce the private data members and public methods with their exact naming and data type. Note that when a Dice object is created, it's internal counts of how many 1s 2s 3s etc have been rolled are stored in a private array of int. Each time a dice is .roll()'d that roll increments that Die's 1s 2s 3s 4s 5s 6s with equal probability. Thus, you must use a Random variable inside your Dice class to get a 1 in 6 chance of getting a 1,2,3,4,5 or 6. Once the roll method decided that a certain number was rolled, the roll method increments the appropriate counter and then returns 1,2,3,4,5 or 6. The reset() method starts that die's counters back at 0.

Start with DiceTester.java

/* DiceTester.java - tests the Dice class DO NOT MODIFY */ public class DiceTester { public static void main( String args[] ) { Dice die1 = new Dice(17); Dice die2 = new Dice(3); // ROLL DICE 20 TIMES PRINT RESULTS System.out.println(" Rolling a pair of dice 20 times."); for (int i=0 ; i<20 ; ++i) system.out.print( die1.roll() + "," die2.roll() " ");> 

I SEEDED each Dice object with a different seed from main. Thus each Dice does not produce identical rolls BUT your program should give IDENTICAL results to my program every time

Here is the output of DiceTester.java

Rolling a pair of dice 20 times. 1,3 1,3 5,1 3,2 5,1 4,1 5,4 4,5 5,2 1,2 2,4 4,5 5,6 4,5 1,4 1,5 2,1 4,4 2,5 6,2 die1 stats: 1: 5 2: 3 3: 1 4: 5 5: 5 6: 1 die2 stats: 1: 4 2: 4 3: 2 4: 4 5: 5 6: 1 Rolling a pair of dice 20 times. 6,2 4,1 4,2 3,6 5,5 6,2 1,6 4,6 1,3 3,6 1,3 2,6 6,1 6,1 3,3 3,4 1,4 5,1 6,4 6,2 die1 stats: 1: 4 2: 1 3: 4 4: 3 5: 2 6: 6 die2 stats: 1: 4 2: 4 3: 3 4: 3 5: 1 6: 5

Code:

/*

DiceTester.java - tests the Dice class

DO NOT MODIFY

*/

public class DiceTester

{

public static void main( String args[] )

{

Dice die1 = new Dice(17);

Dice die2 = new Dice(3);

// ROLL DICE 20 TIMES PRINT RESULTS

System.out.println(" Rolling a pair of dice 20 times.");

for (int i=0 ; i<20 ; ++i)

System.out.print( die1.roll() + "," + die2.roll() + " "); // Each dice equal chance of 1,2,3,4,5 or 6

System.out.println();

System.out.println("die1 stats:");

die1.printStats();

System.out.println("die2 stats:");

die2.printStats();

die1.reset(); // resets all roll counts to 0

die2.reset(); // resets all roll counts to 0

// ROLL DICE 20 TIMES PRINT RESULTS

System.out.println(" Rolling a pair of dice 20 times.");

for (int i=0 ; i<20 ; ++i)

System.out.print( die1.roll() + "," + die2.roll() + " "); // Each dice equal chance of 1,2,3,4,5 or 6

System.out.println();

System.out.println("die1 stats:");

die1.printStats();

System.out.println("die2 stats:");

die2.printStats();

die1.reset(); // resets all roll counts to 0

die2.reset(); // resets all roll counts to 0

}// END main

}//EOF

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!