Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 the 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 computers result as a String. (e.g. if the case matches 0, then the computers 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 o You may also use the logical && operator to combine conditions! 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).

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.

Here is a sample of the solution: 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions