Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Rock Paper Scissors Rock Paper Scissors is a common game that is often used to pass time (or sometimes to make decisions.) The basic rules

Rock Paper Scissors

Rock Paper Scissors is a common game that is often used to pass time (or sometimes to make decisions.) The basic rules of the game are:

Rock crushes Scissors

Paper covers Rock

Scissors cuts Paper

Write a Java program that simulates the game of Rock Paper Scissors.

The user should be able to enter Rock for Rock, Paper for Paper, or Scissors for Scissors.

The code should also ensure that the user only enters R, P, or S (and they should be able to enter upper or lower case versions).

The computer should generate a random value 0 1 or 2 that would be translated into R P or S respectively.

The program then determines according to the rules above who wins the game.

Extra credit (15 points): 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.

Your program should include:

Scanner class for input. The input entered would be a string.

Use the equalsIgnoreCase method to simplify the comparison

A while loop for checking the input

Random class for generating a 0, 1 or 2

A switch statement to assign:

Rock if the number is 0

Paper if the number is 1

Scissors if the number is 2

(you will not need a default if the random number is generated correctly)

Nested if else statements to determine the winner.

Tip: You can use the options shown below to design this portion of the code. Note that there is only one option for a tie.

You can also use the logical && operators in your design, but it is not required.

The possible options for the game are as follows:

Person Computer Winner

Same choice (R, P or S) Same choice (R, P or S) Tie

Rock Scissors Person

Rock Paper Computer

Scissors Rock Computer

Scissors Paper Person

Paper Rock Person

Paper Scissors Computer

For extra credit:

A do while loop to replay the game.

Another while loop to verify the responses to replay the game it should be either yes or no.

A sample of the output is shown below:

Let's play Rock, Paper or Scissors! Enter your choice: Rock, Paper, or Scissors: Rock Computer chooses Rock It's a tie! Play again? Enter yes or no: yes Let's play Rock, Paper or Scissors! Enter your choice: Rock, Paper, or Scissors: Towel Illegal choice: Towel Re-enter your play: Scissors Computer chooses Paper Scissors cut paper. You win!! Play again? Enter yes or no: nah Sorry, that is invalid. Enter yes or no: no

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

Students also viewed these Databases questions

Question

Brief the importance of span of control and its concepts.

Answered: 1 week ago

Question

What is meant by decentralisation?

Answered: 1 week ago

Question

Write down the Limitation of Beer - Lamberts law?

Answered: 1 week ago