Static


Static

EvilRobot class with static
EvilRobotHarness


Classwork


Create a class Die representing a die to roll randomly.

Give Die an int FACES, representing how many faces all dice will have for this run of the program. Make it public, static, and final.

In a static block, choose a value for FACES that is a randomly chosen from the options 4, 6, 8, 10, 12, and 20.

Give Die an instance variable current, representing the last value it rolled.  This cannot be less than 1 or more than FACES

Give Die int instance variables maxCount and minCount.  These cannot be negative.

Give Die a method roll that randomly sets current to a value between 1 and FACES.  If the die rolls a 1, increase minCount, if the die rolls FACES, increase maxCount.

Give Die a static method sumDice, which takes a variable length parameter list of Dies and returns the sum of all their current values.

Give Die a static method sameDice, which takes a variable length parameter list of Dies, and returns true only if all of them have the same current value.  Do not compare the same two dice for equality twice while doing this.

Give Die a static method differentDice, which takes a variable length parameter list of Dies, and returns true only if no two Dies have the same value. Do not compare the same two dice for equality twice while doing this.

Give Die a static method dieStats which takes two ints, howMany and frequency.  In the method, create howmany Dies, and roll them frequency times.  At the end, report how often they rolled all the same, how often they rolled all different, and the average of their sums

[EC] Give Die a private static final int TARGET, and in the static block set it to a random value from 1 to FACES.  Give Die a static method meetsTarget that takes an int frequency and creates and rolls one Die that many times and reports how often out of frequency rolls the die rolled the target or higher.

In a separate class with a main, test these.