Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

could you please try to find what my coding in java program missing so it look like the output! i'm suppose to code RockPaperScissorsEnhance game,

could you please try to find what my coding in java program missing so it look like the output!

i'm suppose to code

RockPaperScissorsEnhance game,

in which the computer randomly chooses rock, paper or scissors(without revealing it).

I already did this :

import java.util.Random;

import java.util.Scanner;

public class rockPaperScissors {

public static void main(String[] args) {

while(true) {

System.out.println("Rock-Paper-Scissors Game");

System.out.println("Please enter your choice.");

System.out.println("Type in 1 for rock, 2 for paper or 3 for scissors, and press enter.");

Scanner choice = new Scanner(System.in);

int rps = choice.nextInt();

Random cChoice = new Random();

int cChoiceRand = cChoice.nextInt(3) + 1;

if(rps<4 && rps>0) {

if (rps == 1)

System.out.println("You chose: Rock");

if (rps == 2)

System.out.println("You chose: Paper");

if (rps == 3)

System.out.println("You chose: Scissors");

if (cChoiceRand == 1)

System.out.println("The computer chose: Rock");

if (cChoiceRand == 2)

System.out.println("The computer chose: Paper");

if (cChoiceRand == 3)

System.out.println("The computer chose: Scissors");

System.out.println("The result is:");

if (rps == cChoiceRand)

System.out.println(" a tie");

if (rps == cChoiceRand+1)

System.out.println(" you win");

if (rps == cChoiceRand-1)

System.out.println(" the computer wins");

if (rps==1 && cChoiceRand==3)

System.out.println(" you win");

if (rps==3 && cChoiceRand==1)

System.out.println(" the computer wins");

System.out.println(" GoodBye! ");

System.out.println("--------------------------------------------------------------------");

}

if (rps>3 || rps<1) {

System.out.println("That is not a choice. Please type in 1 for rock, 2 for paper or 3 for scissors, and press enter.");

System.out.println("------------------------------------------------------------------------------------------------");

}

}

}

}

but the New

Output should look like this with Valid inputs:

********Rock Paper Scissors***************

Enter one of the following:

-- Rock

-- Paper

--Scissors

Rock

You picked rock

Computer picked rock

Winner: Tie

Do you want to play again : Y/N ?

y

********Rock Paper Scissors***************

Enter one of the following:

-- Rock

-- Paper

--Scissors

Scissors

You picked scissors

Computer picked rock

Winner: Computer

Do you want to play again : Y/N ?

y

********Rock Paper Scissors***************

Enter one of the following:

-- Rock

-- Paper

--Scissors

paper

You picked paper

Computer picked rock

Winner: You

Do you want to play again : Y/N ?

N

You won 1 times.

You lost 1 times.

We tied 1 times.

Good Bye!

********Rock Paper Scissors***************

Enter one of the following :

-- Rock

-- Paper

--Scissors

Scissors

You picked scissors

Computer picked paper

Winner: You

Do you want to play again : Y/N ?

y

********Rock Paper Scissors***************

Enter one of the following :

-- Rock

-- Paper

--Scissors

rack

Invalid Choice!

Do you want to play again : Y/N ?

y

********Rock Paper Scissors***************

Enter one of the following :

-- Rock

-- Paper

--Scissors

Rock

You picked rock

Computer picked paper

Winner: Computer

Do you want to play again : Y/N ?

n

You won 1 times.

You lost 1 times.

We tied 0 times.

Goodbye!!

How should i code it so it look like the output?please

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_2

Step: 3

blur-text-image_3

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

=+What policies would lead to this result?

Answered: 1 week ago