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 Your number is: 2 Computer's number is: 3 Computer Wins! ----------------------------------------------------------- The score is: You: 0 Computer: 2 Your number is: 2 Computer's number is: 3 Computer Wins! ----------------------------------------------------------- The score is: You: 0 Computer: 3 Your number is: 1 Computer's number is: 2 Computer Wins! ----------------------------------------------------------- The score is: You: 0 Computer: 4 Your number is: 1 Computer's number is: 5 Computer Wins! That was the last match! I won! Thank you for playing with me!

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 27PE
icon
Related questions
Question

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
Your number is: 2
Computer's number is: 3
Computer Wins!
-----------------------------------------------------------
The score is:
You: 0
Computer: 2
Your number is: 2
Computer's number is: 3
Computer Wins!
-----------------------------------------------------------
The score is:
You: 0
Computer: 3
Your number is: 1
Computer's number is: 2
Computer Wins!
-----------------------------------------------------------
The score is:
You: 0
Computer: 4
Your number is: 1
Computer's number is: 5
Computer Wins!
That was the last match! I won! Thank you for playing with me!

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,