Hi everyone,
I'm new to java. I'm getting an error cannot find symbol m_weapon when i compare char which i assigned from math.random.
Thank you,
public class RPS
{
public static void main (String[ ] args)
{
Scanner console = new Scanner(System.in); //used to gather user input
System.out.println("WELCOME \n\n"+
"This program simulates the Rock Paper Scissors game. \n" +
"The rules are fairly simple. I randomly choose one weapon among Rock, Paper, and Scissors. \n" +
"Then I invite you to choose your weapon. \nYou will have to enter R for Rock, P for Paper, and S for Scissors. \n" +
"The outcome of each battle is determined as follows : \nPaper wins against Rock, Rock wins against Scissors" +
"and Scissors wins against Paper. \n\nWould you like to play with me? (Yes/No)");
String intent;
intent = console.next();
//write a while loop condition that will allow a user to play the game until he/she decides to stop
while(intent.equalsIgnoreCase("Yes"))
{
System.out.println("Please enter a choice of weapon" + "P : Paper / R : Rock / S : Scissors");
char weapon = console.next().charAt(0);
int machine = (int)(Math.random() * 3 + 1);
if (machine == 1)
{
char m_weapon = 'P';
}
else if(machine ==2)
{
char m_weapon = 'R';
}
else if(machine ==3 )
{
char m_weapon = 'S';
}
if (weapon == 'P' && weapon == 'R' && weapon == 'S')
{
System.out.print("tie");
}
if(weapon == 'P' && m_weapon == 'R' || weapon =='R' && m_weapon == 'S'|| weapon =='S' && m_weapon =='P')
{
System.out.println("user wins");
}
else if (weapon == 'R' && m_weapon == 'P' || weapon =='S' && m_weapon == 'R'|| weapon =='P' && m_weapon =='S')
{
System.out.println("machine wins");
}
}
}//closes main
}//closes the class