Please advice on the below issue urgently.........
Write a dice class that takes a variable number of sides. The dice
class should have an explicit roll method that returns the result of a
Dice d20 = new Dice(20);
System.out.println(d20.roll()); // prints 14 (for example)
Optionally, keep track of the last rolled number and provide a get
Often we want to roll multiple dice of the same type and add a fudge
*** This is not the same as multiplying one roll by a number. ***
Modify the dice class to allow the following types of interactions:
// The following simulates rolling 4 20-sided dice and adding 5 to
// the result:
System.out.println(d20.roll(4) + 5); // prints 48 (for example)
// The following simulates rolling 5 20-sided dice and subracting 1
// from the result:
System.out.println(d20.roll(5) - 1); // prints 79 (for example)
Wrap it all up in an interface to re-roll the same types of dice:
Roller x = new Roller(4, 20, 5);
Roller y = new Roller(4, d20, 5);
will both set up a roller that will return 4 * d20 + 5 roll each time.
This should always return a number >= 0, so do not allow Roller() to be
instantiated with values that can result in negative values.