Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java Exercise 4 Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of the common game Rock Paper Scissors that is
Java Exercise 4 Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of the common game Rock Paper Scissors that is often used to pass time (or sometimes to make decisions.) The rules of the game are outlined below: Scissors cuts Paper Paper covers Rock Rock crushes Lizard Lizard poisons Spock Spock smashes Scissors Scissors decapitates Lizard Lizard eats Paper Paper disproves Spock Spock vaporizes Rock Rock crushes Scissors Write a program that simulates the game of Rock Paper Scissors Lizard Spock! The user should be able to enter Strings for each of their choices (e.g. "Rock" for Rock, "Paper" for Paper etc...). O The code should also ensure that the user only enters the strings Rock, Paper or Scissors (and they should be able to enter upper or lower case versions). Use a while loop with the equalsignoreCase method from the String class for best results! The computer should generate a random value 0, 1, 2, 3, or 4 that would be translated into Rock, Paper, Scissors, Lizard or Spock respectively. o Use a switch statement to store the computer's result as a String. (e.g. if the case matches 0, then the computer's choice should be stored as "Rock" in a String variable.) The program then determines according to the rules above who wins the game. o Use nested if else statements to determine the winner 0 You may also use the logical && operator to combine conditions! Extra credit (10 points): Use a do while loop to Modify your program so that it asks the user if they want to replay the game. The program should replay the game as long as the user enters "yes", and quits if the user enters "no". If the user enters a value other than yes or no, the program should ask the user to reenter one of those values (using another while loop for input validation). Extra credit (5 points) If the game is allowed to be replayed, keep track of the number of games played, the number of ties, the number of times the user wins and the number of times the computer wins in the game. At the end of the game (when the user presses no), the program should generate a report showing this data. Tip: This code requires careful planning. Analyze all the possible ways the player and computer can computer can and create an outline (or algorithm or pseudocode) to help you keep track of all of the options! o An algorithm is a step by step set of instructions designed to help you solve the problem. o Psuedocode is "fake code". It is a mixture of text and java syntax that documents the steps in your proposed solution. Here is a sample of the solution (with extra credit parts included): Let's play Rock, Paper, Scissors, Lizard, Spock! Enter your choice: Towel Illegal choice: Towel Re-enter your play: Rock Computer chooses Rock It's a tie! Play again? Enter yes or no: yes Let's play Rock, Paper, Scissors, Lizard, Spock! Enter your choice: Paper Computer chooses Paper It's a tie! Play again? Enter yes or no: yes Let's play Rock, Paper, Scissors, Lizard, Spock! Enter your choice: Scissors Computer chooses Rock Rock crushes Scissors. Computer wins!! Play again? Enter yes or no: yes Let's play Rock, Paper, Scissors, Lizard, Spock! Enter your choice: Lizard Computer chooses Lizard It's a tie! Play again? Enter yes or no: yes Let's play Rock, Paper, Scissors, Lizard, Spock! Enter your choice: Spock Computer chooses Spock It's a tie! Play again? Enter yes or no: yes Let's play Rock, Paper, Scissors, Lizard, Spock! Enter your choice: Paper Computer chooses Lizard Lizard eats paper. Computer wins!! Play again? Enter yes or no: yes Let's play Rock, Paper, Scissors, Lizard, Spock! Enter your choice: Lizard Computer chooses Paper Lizard eats Paper. You win!! Play again? Enter yes or no: yes Let's play Rock, Paper, Scissors, Lizard, Spock! Enter your choice: Spock Computer chooses Paper Paper disproves Spock. Computer wins!! Play again? Enter yes or no: yes Let's play Rock, Paper, Scissors, Lizard, Spock! Enter your choice: Rock Computer chooses Paper Paper covers Rock. Computer wins!! Play again? Enter yes or no: yes Let's play Rock, Paper, Scissors, Lizard, Spock! Enter your choice: Scissors Computer chooses Scissors It's a tie! Play again? Enter yes or no: whatever Sorry, that response is invalid. Enter yes or no: no Number of games played: 10 You won: 1 times ! Computer won: 4 times ! There were: 5 tie games! Thanks for playing
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