Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help generating a program that will act as a virtual Rock, Paper, Scissors game meeting the following requirements. 1.Ask the user to Choose

I need help generating a program that will act as a virtual Rock, Paper, Scissors game meeting the following requirements.

1.Ask the user to "Choose (R)ock, (P)aper, or (S)cissors: ".

a.Note the "( )" indicates that the user should only type the first letter, rather than the entire word.

2.If the user makes a choice other than "R", "P", or "S" then tell them they have made an invalid choice and repeat step 1.Repeat this step until they make a correct choice.

3.Generate a random number for the computer player from among 0, 1, or 2.A 0 will represent a computer player choice of "R", 1 will be "P", and 2 will be "S".

a.Do not worry about how this will be done using code.For now just include this as a step in your flow chart.

4.Display the computer's choice to the user.

5.Determine if the user won, lost, or drew...

a.If the user and the computer made the same choice then display "Draw!"

b.If the user chose "R" and the computer chose "S" OR if the user chose "P" and the computer chose "R" OR if the user chose "S" and the computer chose "P" then display "You win!"

c.Otherwise display "You lose!"

6.Ask the user if they would like to play again.If yes then go back to step 1 and repeat the whole game.The user should be able to play as many times as they like in this way, and be sure that the computer is generating a new random choice each game.

I think I have how to generate a random integer for the computer player (below), but don't know where to go from there.

int randNum = (int) (Math.random() * 3);

String compChoice = "";

switch (randNum) {

case 0:

compChoice = "R";

break;

case 1:

compChoice = "P";

break;

case 2:

compChoice = "S";

break;

}

System.out.println("The computer entered \"" + compChoice + "\".");

Thanks!

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

Students also viewed these Programming questions

Question

run a full Walkthrough of the below pseudo code. (As table) \f

Answered: 1 week ago

Question

ASCII stand for?

Answered: 1 week ago