Question
Write a Java program that allows a player to play a game with a computer. There are two dice (each will randomly show numbers 1,
Write a Java program that allows a player to play a game with a computer. There are two dice (each will randomly show numbers 1, 2, 3, 4, , and 6 after it is rolled) The you and computer will roll. Your program uses a random object to simulate rolling a die by generating a random number between 1 and 6 for you and the computer. You roll two dice and add the two numbers that the dice show , store the sum in a variable called mysum. Then computer is allowed to roll two dice and it computes the sum of the two numbers and save it in a another variable call ed computersum, the following rules determine who wins the game:
1. If mysum=11, you win the game no matter what computersum is.
2. If computersum=7, computer wins the game no matter what my you get.
3. If computer gets 7 and you get 11 at the same time, its a tie, otherwise whoever gets the higher sum wins that game.
At the beginning your program displays a welcome message "Welcome to the Game with a Computer", it first displays the two numbers you roll and the sum you get, it then displays the two numbers computer rolls plus the sum, it finally displays you wins or it is a tie. After one game, your program asks user if he/she wants to continue. When the user decides to stop playing, your program displays a Thank you for playing message.
Bonus: Display total games played, how many games you win, lose and tie.
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