Question: Write a class that should have the following name ,field and methods: LastNameFirstNameDice -sideUp: int + LastNameFirstNameDice() +roll():void +getSideUp():int Write a program that uses the

Write a class that should have the following name ,field and methods:

LastNameFirstNameDice

-sideUp: int

+ LastNameFirstNameDice()

+roll():void

+getSideUp():int

Write a program that uses the Dice class to play a simple dice game between the computer and the user. The program should create two instances of the Dice class. One Dice object is the computers dice , and the other Dice object is the users dice (each a 6-sided dice).

The program should have a loop that iterates 10 times. Each time the loop iterates, it should roll both dice. The dice 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 user.

The sideUP field will hold each possible sides of the dice that is facing up. ( 1 thr 6)

The constructor randomly determines the side of the dice that is facing up (1,2,,6) and initialized the sideUP field accordingly.

roll method that simulates the rolling of the dice. When the roll method is called, it randomly determines the side of the dice that is facing up and sets the sideUP field accordingly.

getSideUp method return the value of the sideUp field.

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!