Question: < > Dice -die:int[] -random:Random +Dice() +Dice(numDice:int) +roll():int -rollDie():int +getDieValues():int[] +hasDoubles():boolean +toString():String java.util.Random // Do a web search for details // and examples +Random(seed:int) +nextInt()

<>

Dice

-die:int[]

-random:Random

+Dice()

+Dice(numDice:int)

+roll():int

-rollDie():int

+getDieValues():int[]

+hasDoubles():boolean

+toString():String

java.util.Random

// Do a web search for details

// and examples

+Random(seed:int)

+nextInt()

+nextInt(limit:int)

DiceClient

// Part 2

+main(args:String[])

The UML class diagram shows that the Diceclasshas-a random object as an instance variable as well as an integer array of die. The default constructor will construct a default pair of die whereas the one-argument constructor will allow the construction of any number of dice (e.g. perhaps we want to play Yahtzee which uses five dice). The principle operation is the roll() method which will roll all of the dice at once, returning their total value. The implementation of this roll() method must use of (i.e. call) a private method rollDie() which rolls a single die and ensures that this rolled value is between 1 and 6, inclusive. The class has two getter-type methods: (1) getDieValues() returns an array of all the individual die-values and (2) hasDoubles() returns true if there are any double-values amongst the die-values. Finally, as you will see in this course, every good class has a toString() method. The format required for the String returned by this method is as follows: a space-separated list of all the individual die-values. Example: For two dice, the toString() method should return 4 6 .

Refer now back to the original UML class diagram. The DiceClientclass has a single method called main().

Your code must generate a statistical sample set of 2000 dice-rolls from which it will print out a histogram of the 4000 values (2000 rolls of a pair of dice = 4000 die values) as well as their average and standard deviation. Check out this URL for calculating the standard deviation: https://www.strchr.com/standard_deviation_in_one_pass

Sample output that you are to replicate in your program is shown below, to help you understand the task at hand.

The average roll was 3.48475

The standard deviation of the rolls was 1.721704805563369

The histogram of the rolls is:

1(697) :*********************************************************************

2(660) :******************************************************************

3(650) :*****************************************************************

4(671) :*******************************************************************

5(644) :****************************************************************

6(678) :*******************************************************************

In the histogram, there are 6 lines, one line for each possible value. On each line, the value of the die is printed, followed by the total number of rolls of this value in brackets, followed by a visual representation of this total. A * should be printed for every 10 rolls.

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!