cannot find symbol variable lines 24, 25, 44, 45, 63, 64? Help!
import java.util.Random;
import static java.lang.System.out;
import java.util.Scanner;
class Simulator {
public static void main(String args[]) {
Random myRandom = new Random();
Scanner myScanner = new Scanner(System.in);
char Rock, Paper, Scissors;
char input;
out.println("Welcome to rock/paper/scissors!");
out.println("Which object would you like to choose?");
do {out.println("Invalid input.Please try again.");
} while ((input != 'R') || (input != 'r') || (input != 'P') || (input != 'P') || (input !='S') || (input != 's'));
input = myScanner.findInLine(".").charAt(0);
if ((input == 'R') || (input == 'r')) {
input = Rock;
randomNumber = myRandom.nextInt(8);
switch (randomNumber) {
case 0: out.print("You chose a rock and the computer chose a paper. You lose!");
case 1: out.print("You chose a rock and the computer chose a paper. You lose!");
case 2: out.print("You chose a rock and the computer chose a paper. You lose!");
break;
case 3: out.print("You chose a rock and the computer chose a scissors. You win!");
case 4: out.print("You chose a rock and the computer chose a scissors. You win!");
case 5: out.print("You chose a rock and the computer chose a scissors. You win!");
break;
case 6: out.print("You chose a rock and the computer chose a rock. It's a tie!");
case 7: out.print("You chose a rock and the computer chose a rock. It's a tie!");
case 8: out.print("You chose a rock and the computer chose a rock. It's a tie!");
break;
}
}
if ((input == 'P') || (input == 'p')) {
input = Paper;
randomNumber = myRandom.nextInt(8);
switch (randomNumber) {
case 0: out.print("You chose a paper and the computer chose a paper. It's a tie!");
case 1: out.print("You chose a paper and the computer chose a paper. It's a tie!");
case 2: out.print("You chose a paper and the computer chose a paper. It's a tie!");
break;
case 3: out.print("You chose a paper and the computer chose a scissors. You lose!");
case 4: out.print("You chose a paper and the computer chose a scissors. You lose!");
case 5: out.print("You chose a paper and the computer chose a scissors. You lose!");
break;
case 6: out.print("You chose a paper and the computer chose a rock. You win!");
case 7: out.print("You chose a paper and the computer chose a rock. You win!");
case 8: out.print("You chose a paper and the computer chose a rock. You win!");
break;
}
}
if ((input == 'S') || (input == 's')) {
input = Scissors;
randomNumber = myRandom.nextInt(8);
switch (randomNumber) {
case 0: out.print("You chose a scissors and the computer chose a paper. You win!");
case 1: out.print("You chose a scissors and the computer chose a paper. You win!");
case 2: out.print("You chose a scissors and the computer chose a paper. You win!");
break;
case 3: out.print("You chose a scissors and the computer chose a scissors. It's a tie!");
case 4: out.print("You chose a scissors and the computer chose a scissors. It's a tie!");
case 5: out.print("You chose a scissors and the computer chose a scissors. It's a tie!");
break;
case 6: out.print("You chose a scissors and the computer chose a rock. You lose!");
case 7: out.print("You chose a scissors and the computer chose a rock. You lose!");
case 8: out.print("You chose a scissors and the computer chose a rock. You lose!");
break;
}
}
}
}
Re: cannot find symbol variable lines 24, 25, 44, 45, 63, 64? Help!
Hi IronMan,
Please post your code in
Plus, mention the exact error message from console rather than simply mentioning the error lines. That would help us get to the point quickly.
Thanks for your co-operation.
Goldest
Re: cannot find symbol variable lines 24, 25, 44, 45, 63, 64? Help!
Seems from the overview of the code that the variable "randomNumber" was never declared, but still its getting used in the switch clause. You are trying to use it on every line 24, 25, 44, 45, 63, 64 and thats where the errors are coming from.
First declare the variable [int randomNumber] and then use it, otherwise the compiler will complain with the message "cannot find symbol".
I hope you have the clear idea now.
Goldest