Question: One die can be thrown to randomly show a value from 1 through 6. Design a Die class that can hold an integer data field
One die can be thrown to randomly show a value from 1 through 6. Design a Die class that can hold an integer data field named v for a value. Include a default constructor that assigns the variable v the default value of 0. Die class should also consist of a method that gets the value of the field v. Create another method called roll that randomly sets the value of the filed v to an integer value between 1 and 6. This roll method can return the integer value as the result of the die throw. Use the Math.random() function to randomly generate a value between 0 and 1 and then apply the appropriate manipulation to receive an integer value between 1 and 6.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
