Question: Write java code to create dice program The UML class diagram shows that the Dice class has-a Random object as an instance variable as well

Write java code to create dice program

The UML class diagram shows that the Dice class has-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 .

Write java code to create dice program The UML class diagram shows

Dice iava.util.Random -die:int[ -random Random // Do a web search for details // and examples +Random(seed:int) +nextlnt) +nextlnt(limit:int)* +Dice()- +Dice(numDice:int)v +roll(:int -rollDie()int DiceClient // Part 2 +main(args:String[]) +getDieValues():intll +hasDoubles():boolean +toString():String

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!