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.


[EC]

Create a separate class AutoCode.

In AutoCode, create a static method autoGet which takes a String type and a String name, and returns a String consisting of a basic accessor for a variable with that name and that type (don't worry about camel casing)  Do use \n and \t to correctly format your code.

In AutoCode create a similar method autoSet that generates a mutator.

In AutoCode, override autoSet to also have a version that takes an int min and and int max.  In this method, if type is "int" or "double" (you can include other numeric primitive types if you like), have the mutator you generate include validation making sure that the new value is between (inclusive) min and max.  Otherwise ignore max and min.

In your main, test these.