JAVA In the game Rock Paper Scissors two players simultaneou
JAVA:
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: Rock beats scissors, because a rock can break a pair of scissors. Scissors beats paper, because scissors can cut paper. Paper beats rock, because a piece of paper can cover a rock. Create a game in which the computer randomly chooses rock, paper, or scissors. Let the user enter a number 1, 2, or 3, each representing one of the three choices. Then, determine the winner. Save the application as RockPaperScissors.java.
Solution
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
import java.util.Random;
public class Main {
public static void main(String[] args) throws java.lang.Exception {
Scanner inp = new Scanner(System. in );
Random rnd = new Random();
int input;
int B = 1;
System.out.println(\"Pick 1,2, or 3 for:\");
System.out.println(\"ROCK (1), PAPER(2), or SCISSOR (3)\");
while (B != 0) {
int Rock = 1, Paper = 2, Scissor = 3;
input = inp.nextInt();
int randomNumber = rnd.nextInt(3 - 1 + 1) + 1;
if (randomNumber == Rock) {
if (input == Rock) {
System.out.println(\"Rock Vs. Rock: TIE\");
} else if (input == Paper) {
System.out.println(\"Paper Vs. Rock: YOU WIN\");
} else if (input == Scissor) {
System.out.println(\"Scissor Vs. Rock: YOU LOSE\");
}
} else if (randomNumber == Paper) {
if (input == Rock) {
System.out.println(\"Rock Vs. Paper: YOU LOSE\");
} else if (input == Paper) {
System.out.println(\"Paper Vs. Paper: TIE\");
} else if (input == Scissor) {
System.out.println(\"Scissor Vs. Paper: YOU WIN\");
}
} else if (randomNumber == Scissor) {
if (input == Rock) {
System.out.println(\"Rock Vs. Scissor: YOU WIN\");
} else if (input == Paper) {
System.out.println(\"Paper Vs. Scissor: YOU LOSE\");
} else if (input == Scissor) {
System.out.println(\"Scissor Vs. Scissor: TIE\");
}
}
int Y=1, N=0;
System.out.println(\"Do you want to play again? Y(1)/N09)\");
input = inp.nextInt();
if(input==Y){
B=1;
System.out.println(\"ROCK (1), PAPER(2), or SCISSOR (3)\");
}
else if(input==N){
System.exit(0);
System.out.println(\"GOODBYE\");
}
}
}
}

