• Write a class Die which has members & methods: •int sides : # of sides for the
ID: 3705762 • Letter: #
Question
• Write a class Die which has members & methods:
•int sides: # of sides for the die
•int value: value of the die
•String owner: Name of player holding the die
•Methods:
•Appropriate constructors.
•Set/get for sides, value and owner.
•roll(): creates a random object and uses it to set value to a random number.
•Write a main method that has the computer play against the user.
•Ask the user for their name. Create a die for the user and one for the computer.
•Ask the user how many sides they want the die to have.
•Ask the user how many iterations they want to play with.
•Create a loop that runs for the iterations specified by the user. In each iteration roll both die and check
which one has a larger value. The die with the larger value gets a point. In case of a tie, no one gets a
point. At the end, print the score and the name of the winner.
NO import java.util.concurrent.TimeUnit;
CODE IN JAVA
Explanation / Answer
Hi Dear,
Please find my implementation.
Output:
Enter name: Pravesh Kumar
How many sides: 6
How many iteration: 10
User points: 4
Computer points: 2
User WON!!
Process finished with exit code 0
Please DONT forgot to rate my answer. We are working hard for you Guys!!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.