Question: 1. Write a java program that allows a user to play 5 rounds of Rock-Paper-Scissors against a computer opponent. The user will be prompted with

1. Write a java program that allows a user to play 5 rounds of Rock-Paper-Scissors against a computer opponent. The user will be prompted with a choice between Rock, Paper and Scissors. A random selection between Rock, Paper and Scissors is made on behalf of the computer. The result of the round will be printed to the console along with the users statistics. When all rounds are complete, print the users win percentage. A round has only two possible outcomes: a draw, or a win for one player and a loss for the other. A draw happens when both players choose the same item. The following shows which items win over other items. Rock beats Scissors Paper beats Rock Scissors beats Paper Requirements For each round, print the number of the round. Use the following text: Round {number}

Prompt the user for their choice of Rock-Paper-Scissors using the following text: Enter your choice (1 - Rock, 2 - Paper, 3 - Scissors): {user_response} When the user enters an invalid choice, print the error message Invalid Choice!. Prompt the user to enter a new choice. Use the following text: Invalid choice! (1, 2 or 3): {user_response} NOTE: Continue to prompt the user for a choice until they enter a valid integer. Your program will chose an item for the computer player at random. Print the choice made by the computer to the console: Computer chose {choice}. A round is completed when a winner is determined. In the case of a draw, print the following message to the console: The round is a draw. Replay the round until there is a winner. When a winner is determined, print a message indicating which item beat the other item followed by the winners name (Player or Computer). Use the following text and format: {winner_choice} beats {loser_choice}, {player} wins!

At the end of each round print a message indicating how many rounds the user has won. Use the following text and format: You have won {number_of_rounds_won} of {number_of_rounds_played} rounds. Leave one blank line between each round. After the last round, print a message indicating the users win percentage. Ensure the percentage is formatted to zero decimal places (example: 57%). Use the following text and format: Your win percentage is {percentage}. Sample Output: Round 1 Enter your choice (1 - Rock, 2 - Paper, 3 - Scissors): 3 Computer chose Rock. Rock beats Scissors, Computer wins! You have won 0 of 1 rounds. Round 2 Enter your choice (1 - Rock, 2 - Paper, 3 - Scissors): 9 Invalid choice! (1, 2 or 3): -1 Invalid choice! (1, 2 or 3): 2 Computer chose Rock. Paper beats Rock, Player wins! You have won 1 of 2 rounds. Round 3

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!