Has to compile in jGrasp and THIS CANNOT BE USED: Rock, Paper, Scissors is a two
ID: 3849149 • Letter: H
Question
Has to compile in jGrasp and THIS CANNOT BE USED:
Rock, Paper, Scissors is a two player game, where each player simultaneously chooses one of the three items after counting to three. The game typically lasts a pre-determined number of rounds. The player who wins the most rounds wins the game. Given the number of rounds in which the players will compete, it is your job to determine which player wins after those rounds have been played.
The rules for what item wins are as follows:
Rock always beats Scissors (Rock crushes Scissors)
Scissors always beat Paper (Scissors cut Paper)
Paper always beats Rock (Paper wraps Rock)
Input (from file a.txt)
The first value in the input file will be an integer t (0 < t < 1000) representing the number of test cases in the input file. Following this, on a case by case basis, will be an integer n (0 < n < 100) specifying the number of rounds of Rock, Paper, Scissors played. Next will be n lines, each with either a capital R, P, or S, followed by a space, followed by a capital R, P, or S, followed by a newline. The first letter is Player 1’s choice; the second letter is Player 2’s choice.
Output (to monitor)
For each test case, report the name of the player (Player 1 or Player 2) that wins the game, followed by a newline. If the game ends up in a tie, print TIE.
Sample Input
3
2
RP
SR
3
PP
RS
SR
1
PR
Sample Output
Player 2
TIE
Player 1
Explanation / Answer
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
import java.util.Random;
/* Name of the class has to be "Main" only if the class is public. */
public class HelloWorld {
public static void main(String[] args) throws java.lang.Exception {
Scanner Ilya = new Scanner(System. in );
Random rnd = new Random();
int input;
int B = 1;
System.out.println("ILYA IS THE GREATEST");
System.out.println("Pick 1,2, or 3 for:");
System.out.println("ROCK (1), PAPER(2), or SCISSOR (3)");
while (B != 0) {
// 1 = rock
// 2 = paper
// 3 = scissors
// N= Ilya.nextInt();
int Rock = 1, Paper = 2, Scissor = 3;
input = Ilya.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=8, N=9;
System.out.println("Do you want to play again? Y(8)/N(9)");
input = Ilya.nextInt();
if(input==Y){
B=1;
System.out.println("Rock, Paper,SCISSOR");
}
else if(input==N)
{System.exit(0);
System.out.println("GOODBYE");
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.