package javaPackage;
import javax.swing.*;
import java.util.*;
public class Random
{
public static void main (String[] args)
{
Random input = new Random();
String games = "", roundTwo = "";
int user = 0, comp = 0, result = 0;
games = JOptionPane.showInputDialog(null, "Enter a number: \n1. Rock" +
"\n2. Paper \n3. Scissors: ", "Decision", JOptionPane.INFORMATION_MESSAGE);
user = Integer.parseInt(games);
comp = (int) (Math.random() *3);
JOptionPane.showMessageDialog(null, "The computer's choice is: " +
(comp+1), "Computer", JOptionPane.INFORMATION_MESSAGE);
if (user == 1 && comp == 0)
{
JOptionPane.showMessageDialog(null, "The match is draw.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if(user ==1 && comp == 1)
{
JOptionPane.showMessageDialog(null, "The computer won.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if(user ==1 && comp == 2)
{
JOptionPane.showMessageDialog(null, "You won.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if(user == 2 && comp == 0)
{
JOptionPane.showMessageDialog(null, "You won.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if (user == 2 && comp == 1)
{
JOptionPane.showMessageDialog(null, "The match is draw.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if (user == 2 && comp ==2)
{
JOptionPane.showMessageDialog(null, "The computer won.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if (user == 3 && comp ==0)
{
JOptionPane.showMessageDialog(null, "The computer won.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if (user == 3 && comp == 1)
{
JOptionPane.showMessageDialog(null, "You won.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if(user==3 && comp == 2)
{
JOptionPane.showMessageDialog(null, "The match is draw.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else
JOptionPane.showMessageDialog(null, "Invalid input.", "Error",
JOptionPane.ERROR_MESSAGE);
roundTwo = JOptionPane.showInputDialog(null, "Another round? 0 if no, 1 if yes ", "Round",
JOptionPane.INFORMATION_MESSAGE);
result = Integer.parseInt(roundTwo);
while (result == 1)
{
games = JOptionPane.showInputDialog(null, "Enter a number: \n1. Rock" +
"\n2. Paper \n3. Scissors: ", "Decision", JOptionPane.INFORMATION_MESSAGE);
user = Integer.parseInt(games);
comp = (int) (Math.random() *3);
JOptionPane.showMessageDialog(null, "The computer's choice is: " +
(comp+1), "Computer", JOptionPane.INFORMATION_MESSAGE);
if (user == 1 && comp == 0)
{
JOptionPane.showMessageDialog(null, "The match is draw.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if(user ==1 && comp == 1)
{
JOptionPane.showMessageDialog(null, "The computer won.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if(user ==1 && comp == 2)
{
JOptionPane.showMessageDialog(null, "You won.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if(user == 2 && comp == 0)
{
JOptionPane.showMessageDialog(null, "You won.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if (user == 2 && comp == 1)
{
JOptionPane.showMessageDialog(null, "The match is draw.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if (user == 2 && comp ==2)
{
JOptionPane.showMessageDialog(null, "The computer won.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if (user == 3 && comp ==0)
{
JOptionPane.showMessageDialog(null, "The computer won.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if (user == 3 && comp == 1)
{
JOptionPane.showMessageDialog(null, "You won.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else if(user==3 && comp == 2)
{
JOptionPane.showMessageDialog(null, "The match is draw.", "Result",
JOptionPane.INFORMATION_MESSAGE);
}
else
JOptionPane.showMessageDialog(null, "Invalid input.", "Error",
JOptionPane.ERROR_MESSAGE);
roundTwo = JOptionPane.showInputDialog(null, "Another round? 0 if no, 1 if yes ", "Round",
JOptionPane.INFORMATION_MESSAGE);
result = Integer.parseInt(roundTwo);
}
}
}