Hey guys, im doing a rock paper scissors program for h/w i got it done but im getting an error and i cant figure out whats wrong.
public static void main(String[] args)
{
int pcpick;
int userpick;
String userChoice = JOptionPane.showInputDialog("1 Rock, 2 Paper, 3 Scissors");
int choice = Integer.parseInt(userChoice);
switch (choice)
{
case 1:
userpick = 1;
break;
case 2:
userpick = 2;
break;
case 3:
userpick = 3;
break;
default:
System.out.println("ERROR");
break;
}
Random gen = new Random();
int pcnum;
pcnum = gen.nextInt(3) + 1;
switch (pcnum)
{
case 1:
pcpick = 1;
break;
case 2:
pcpick = 2;
break;
case 3:
pcpick = 3;
break;
default:
System.out.println("Error");
break;
}
if (pcpick == 1)
{
if(userpick==1)
System.out.println("You both picked rock, it's a tie!");
if(userpick==2)
System.out.println("PC picked rock you picked paper, you win!");
if(userpick==3)
System.out.println("PC picked rock you picked scissors, you lose!");
}
if (pcpick == 2)
{
if(userpick==1)
System.out.println("PC picked paper you picked rock, you lose!");
if(userpick==2)
System.out.println("You both picked paper, it's a tie!");
if(userpick==3)
System.out.println("PC picked paper you picked scissors, you win!");
}
if (pcpick == 3)
{
if(userpick==1)
System.out.println("PC picked scissors you picked rock, you win!");
if(userpick==2)
System.out.println("PC picked scissors you picked paper, you lose!");
if(userpick==3)
System.out.println("You both picked scissors, it's a tie!");
}
The above is all my code... im using BLUEJ. it highlights
if (pcpick == 1)
and states "variable pcpick might not have been initialized." Let me know what you think!
im thinking i didnt do the "cases" right