Write a program that plays the popular scissor-rock-paper game. The program randomly generates a number 0, 1, or 2 representing scissor, rock, and paper. The program prompts the user to enter a number 0, 1, or 2 and display a message indicating whether the user or the computer wins, loses, or draws. Revise the program to let the user continuously play until either the user or the computer wins more than two times.
import javax.swing.JOptionPane;
import java.util.Scanner;
public class projrct
{
public static void main(String[] args)
{
int computer, you, win_of_computer = 0, win_of_you = 0;
Scanner input = new Scanner(System.in);
int option = JOptionPane.YES_OPTION;
// Game start
while (option == JOptionPane.YES_OPTION)
{
win_of_computer = 0;
win_of_you = 0;
while(win_of_computer-win_of_you!=2&&win_of_you- win_of_computer!=2)
{
computer = (int) (Math.random() * 3);
System.out.print("scissor(0),rock(1),paper(2):");
you = input.nextInt();
if (computer == 0)
{
if (you == 0)
System.out.println("The computer is scissor. You are scissor too. It is a draw");
else if (you == 1)
{
System.out.println("The computer is scissor. You are rock. You won");
win_of_you++;
}
else
{
System.out.println("The computer is scissor. You are paper. You lose");
win_of_computer++;
}
}
else if (computer == 1)
{
if (you == 0)
{
System.out.println("The computer is rock. You are scissor. You lose");
win_of_computer++;
}
else if (you == 1)
System.out.println("The computer is rock. You are rock too. It is a draw");
else
{
System.out.println("The computer is rock. You are paper. You won");
win_of_you++;
}
}
else
{
if (you == 0)
{
System.out.println("The computer is paper. You are scissor. You won");
win_of_you++;
}
else if (you == 1)
{
System.out.println("The computer is paper. You are rock. You lose");
win_of_computer++;
}
else
System.out.println("The computer is paper. You are paper too. It is a draw");
}
}
// print game result
if (win_of_computer > win_of_you)
System.out.println("The computer won finally");
else
System.out.println("You won finally");
option = JOptionPane.showConfirmDialog(null, "Do you want play again?");
}
}
}