Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Must in be Java! This program allows a user to play Rock, paper, scissors against the computer. Use a random number generator to generate the

Must in be Java!

This program allows a user to play Rock, paper, scissors against the computer. Use a random number generator to generate the computers selection. Your code should ask the user what they choose and then report the computers choice and who wins.

This code should run in a loop and should end when the user chooses to end. (Make sure your random number generator chooses a new number each time the loop runs.)

ALSO, your code should keep track of the number of times you win, the number of times you lose, and the number of ties. When the user exits, these statistics should be displayed. (Consider using a different counter variable to keep track of each value.)

Make sure your code accounts for inputs that are out of the acceptable range. For example, if you ask the user to type 0 to end, 1 for Rock, 2 for Paper, and 3 for Scissors, your code should tell the user that they entered an invalid choice if they select 4. (You do not have to account for users who crash the program by entering Strings when an integer is expected.)

Theres some example output below. Your output messages should be an exact match to the sample output (except for results that differ due to randomness). In particular, do not change the text, ordering of choice, or anything else in the introductory message to the user.

Output Example (User input is marked with >>>. Everything else is what you print to the screen.)

Lets play Rock, Paper, Scissors! Make your selection: (1 for Rock, 2 for Paper, 3 for Scissors, 0 to End)

>>>3

You chose scissors. The computer chose rock. You lose!

Lets play Rock, Paper, Scissors! Make your selection: (1 for Rock, 2 for Paper, 3 for Scissors, 0 to End)

>>>1

You chose rock. The computer chose scissors. You win!

Lets play Rock, Paper, Scissors! Make your selection: (1 for Rock, 2 for Paper, 3 for Scissors, 0 to End)

>>>1

You chose rock. The computer chose rock. Its a tie!

Lets play Rock, Paper, Scissors! Make your selection: (1 for Rock, 2 for Paper, 3 for Scissors, 0 to End)

>>>2

You chose paper. The computer chose paper. Its a tie!

Lets play Rock, Paper, Scissors! Make your selection: (1 for Rock, 2 for Paper, 3 for Scissors, 0 to End)

>>>4

Invalid selection.

Lets play Rock, Paper, Scissors! Make your selection: (1 for Rock, 2 for Paper, 3 for Scissors, 0 to End)

>>>0

You won 1 time.

The computer won 1 time.

You tied with the computer 2 times.

Thanks for playing! Goodbye!

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 Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions