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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!