APCS-A Java Classwork: Dice Roll
Create a non-static class named 'DiceRoll' in its own file. The class
should contain a single constructor that takes two positive integers as its
arguments, representing the number of sides of two separate fair dice.
For example, a call such as
DiceRoll dice = new DiceRoll(6, 10);
will create a new DiceRoll object called 'dice' that will set up a six-sided
die (numbered 1 through 6) and a ten-sided die (numbered 1 through 10).
Remember that the above call to 'DiceRoll' is an example. No specific dice
values should appear anywhere in the 'DiceRoll' class. The one exception
to this is if a non-positive integer is submitted to either the constructor
or the 'changeDice' method. Any die assigned a non-positive number of sides
should instead be made into a six-sided die.
The method 'main' and the keyword 'static' must not appear anywhere in the
'DiceRoll' class. Make sure all of the internal variables in the 'DiceRoll'
class are private. The class should contain the following public methods:
newRoll
Arguments: None
Actions: "Rolls" both dice and stores the result of the rolls
Displays: Nothing
Returns: Nothing
-------------
lastRoll
Arguments: None
Displays: Nothing
Returns: A string containing BOTH of the die values from the last
(most recent) time that the dice were rolled; the string
should have the form "#, #" (e.g., "2, 9", but without the
quotes); if this method is called before the current dice
have been rolled for the first time (or right after the
'reset' method has been called), an empty string should be
returned
-------------
sum
Arguments: None
Displays: Nothing
Returns: An integer equal to the sum of the most recent roll of the
two CURRENT dice; if the dice have not yet been rolled (or
if the 'reset' method has just been called), a zero should
be returned
-------------
total
Arguments: None
Displays: Nothing
Returns: An integer equal to the sum of ALL of the rolls so far of
the two CURRENT dice; if the dice have not yet been rolled
(or if the 'reset' method has just been called), a zero
should be returned
-------------
reset
Arguments: None
Actions: Resets the internal "sum" and "total" dice values to zero,
and also clears the internal 'last roll' values of the dice
(as if the current dice have never been rolled)
Displays: Nothing
Returns: Nothing
-------------
changeDice
Arguments: Two positive integers representing the number of sides of
two separate fair dice
Actions: Changes the number of sides of the two dice to the newly
supplied values; also calls the 'reset' method to clear
all internal sum values and the roll history
Displays: Nothing
Returns: Nothing
As always, all of your code must be your own, written entirely and
only by you within your online CodeHS.com account. You must never
copy/paste, receive, view, or in any way use code that was created
or modified by another person, entity, or artificial intelligence.
Advanced Option #1
To the 'DiceRoll' class, add another public method named 'cheatRoll' that
functions in the same manner as the 'newRoll' method, except that for each
die, regardless of the number of sides on the die, it should be twice as
likely that an even number (as opposed to an odd number) will be rolled.
Advanced Option #2
To the 'DiceRoll' class, add another public method named 'showLastRoll' that
functions in the same manner as the 'lastRoll' method, except that it returns
nothing, but instead displays a JFrame containing the two values of the most
recent dice roll. It is up to you how you display the two values on the
JFrame (text in labels, graphically with images, large dots, etc.).