Question: Please help me with this in java programming Using the Die class defined in Chapter 4, write a class called WideDie, which can be regarded
Please help me with this in java programming
Using the Die class defined in Chapter 4, write a class called WideDie, which can be regarded as a modification of the Die class, so that the die value will range from 1 to 10 (inclusive). //******************************************************************** // Die.java Author: Lewis/Loftus //
// Represents one die (singular of dice) with faces showing values // between 1 and 6. //******************************************************************** public class Die { private final int MAX = 6; // maximum face value private int faceValue; // current value showing on the die //----------------------------------------------------------------- // Constructor: Sets the initial face value. //----------------------------------------------------------------- public Die() { faceValue = 1; } //----------------------------------------------------------------- // Rolls the die and returns the result. //----------------------------------------------------------------- public int roll() { faceValue = (int)(Math.random() * MAX) + 1; return faceValue; } //----------------------------------------------------------------- // Face value mutator. //----------------------------------------------------------------- public void setFaceValue(int value) { faceValue = value; } //----------------------------------------------------------------- // Face value accessor. //----------------------------------------------------------------- public int getFaceValue() { return faceValue; } //----------------------------------------------------------------- // Returns a string representation of this die. //----------------------------------------------------------------- public String toString() { String result = Integer.toString(faceValue); return result; } } Then write a class called DoubleDice, composed of two WideDie objects. Include methods to set
and get the individual die values, a method to roll the dice, and a method that returns the (non- negative) difference of the two die values. Create a driver class to instantiate and use a
DoubleDice object and illustate the use of all your implemented features. Note: do not directly modify WideDie itself into the DoubleDice class, as this is not what the question is asking for. Calculate the average difference of the die values (the difference between the two dice of a DoubleDice object) for throwing 10, 100, 1000 doubledice respectively.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
