Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a Java program for a Rock-paper-scissors program code with the following rules: The rules of the game are as follows: Each player chooses Rock,
Write a Java program for a Rock-paper-scissors program code with the following rules:
The rules of the game are as follows:
- Each player chooses Rock, Paper, or Scissors.
- If both players (user vs. computer) choose the same thing, the round is a tie.
- Otherwise:
- Paper wraps Rock to win
- Scissors cut Paper to win
- Rock breaks Scissors to win
- The program first asks the user how many rounds he/she wants to play.
- Maximum number of rounds = 10, minimum number of rounds = 1. If the user asks for something outside this range, the program prints an error message and quits.
- If the number of rounds is in range, the program plays that number of rounds. Each round is played according to the requirements below.
- For each round of Rock, Paper, Scissors, the program does the following:
- The computer asks the user for his/her choice (Rock, Paper, or Scissors).
- Hint: 1 = Rock, 2 = Paper, 3 = Scissors
- After the computer asks for the users input, the computer randomly chooses Rock, Paper, or Scissors and displays the result of the round (tie, user win, or computer win).
- Hint: use the Random class.
- The computer asks the user for his/her choice (Rock, Paper, or Scissors).
- The program must keep track of how many rounds are ties, user wins, or computer wins.
- Hint: Create three variables to keep track of these items and update them correctly after each round.
- The program must print out the number of ties, user wins, and computer wins and declare the overall winner based on who won more rounds.
- After all rounds have been played and the winner declared, the program must ask the user if he/she wants to play again.
- If the user says No, the program prints out a message saying, Thanks for playing! and then exits.
- If the user says Yes, the program starts over, asking the user how many rounds he/she would like to play.
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