In JAVA Write a program that simulates a simple dice game between the computer and the user. When the program runs, a loop should run 5 times; in each iteration, the program should • Generate a random integer in the range of 1 to 6 --this is the value of the computer’s die. • Generate another random integer in the range of 1 to 6 --this is the value of the user’s die. The die with the highest value wins. (In case of a tie, there is no winner for that particular roll of
In JAVA
Write a program that simulates a simple dice game between the computer and the user. When the
program runs, a loop should run 5 times; in each iteration, the program should
• Generate a random integer in the range of 1 to 6 --this is the value of the computer’s die.
• Generate another random integer in the range of 1 to 6 --this is the value of the user’s die.
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 count the number of times the computer wins
and the number of times the user wins. In the end, the program should display who was the grand
winner, the computer, or the user. The program should perform input validation for the player’s
input (only ‘y’ or ‘n’ are acceptable).
Sample Run:
Lets play a game of dice! We both roll and whoever is higher after 5 turns wins! Do you want to
play? (y/n) k
Invalid Entry
Lets play a game of dice! We both roll and whoever is higher after 5 turns wins! Do you want to
play? (y/n)y
-----------------------------------------------------------
The score is:
You: 0
Computer: 0
Your number is: 2
Computer's number is: 6
-----------------------------------------------------------
Computer Wins!
-----------------------------------------------------------
The score is:
You: 0
Computer: 1
Step by step
Solved in 3 steps with 1 images