Please help me out I am the biginner in java.I I suppose to write a program that plays the popular rock-paper game.The program should randomly generate the random number 0,1 or 2 representing the rock, paper or scissor. The program should randomly ask the user to enter number 0,1 or 0 and display the message indicating whether the user or the computer wins or draws.
NOTE: A scissor can cut a paper, a rock can crush a scissor and the paper can wrap a rock.
I am require to use math.random() medhod. To get random number between 0 and 2. I am required to use the following code:
(int)(Math.random() *)
Note: Math.radom return a double value between 0 and 1.
Finally JOptionPane is required for input and out.
Here is what i have sor far but I am getting few bugs. Please help I would reallly appreciate.
import javax.swing.JOptionPane; // Need JOptionPane class
import java.util.Random; // Need Random class
public class RockPaperScissorGameJOptionPane{
public static void main(String [] args){
// Please decleare the variables
String inputRock;
String inputScissor;
String inputNumber;
String inputPaper;
int number;
int paper;
int scissor;
int random;
int randomNumber;
int rock;
rock = 0;
paper = 1;
scissor = 2;
// Please prompt the user to enter the number 0, 1, and 2.
JOptionPane.showInputDialog(" Please ask the user to enter number 0,1 2 or enter 4 to exit ");
number = Integer.parseInt(inputNumber);
randomNumber = (int)(Math.random() *3);
switch(number){
case 1:
if(randomNumber == 2){
JOptionPane.showMessageDialog(null, " The computer wins.");
}
else if (randomNumber ==0){
JOptionPane.showMessageDialog(null, " The game is a draw.");
}
else if (randomNumber == 1){
JOptionPane.showMessageDialog(null,"The user is wins.");
}
break;
case 2:
if (randomNumber ==0){
JOptionPane.showMessageDialog(null,"The computer wins.");
}
else if(randomNumber ==1){
JOptionPane.showMessageDialog(null,"The game is draw.");
}
else if(randomNumber == 2){
JOptionPane.showMessageDialog(null,"The user wins.");
}
break;
case 3:
if (randomNumber == 1){
JOptionPane.showMessageDialog(null, " The computer wins.");
}
else if (randomNumber == 2){
JOptionPane.showMessageDialog(null, " The game is a draw.");
}
else if (randomNumber == 0){
JOptionPane.showMessageDialog(null, " The user wins.");
}
break;
case4:
System.exit(0);
}
}
}