Question
Write a program that uses the Die class to play a simple dice game between the computer and the user. The program should create two
Write a program that uses the Die class to play a simple dice game between the computer and the user. The program should create two instances of the Die class (each a 6 side die). One Die object is the computers die and the other Die object is the users die.
The program should have a loop that iterates 10 times. Each time the loop iterates it should roll both dice. The die with the highest value wins. (in case of a tie there is no winner for that particular roll of the dice)
As the loop iterates the program should keep count of the number of times the computer wins, and the number of times that the user wins. After the loop performs all of its iterations, the program should display who was the grand winner the computer or the use. Use following UML diagram to design your class.
Class: Die |
Data Members: -computername: String -username: String -sides : int - value : int |
Method Members: +Die(sides : int) +Die(computename:String,username:String) + getSide() :int + setSide(sides : int) : void + getValue() : int + setValue(value : int) : void +roll() : void +getComputername(): String +setComputername(value: String):void +getUsername(): String +setUsername(value:String): void |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started