Results 1 to 5 of 5
- 12-25-2010, 02:55 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
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;
}
}
}
}
-
So are you going to tell us which lines are the ones indicated or are we supposed to guess?
- 12-25-2010, 03:20 AM #3
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
put your code in code tags next time.
If you see "cannot find symbol" errors, most of the time, its due to variable declaration problems. In that case, try declaring the variable.
Java Code: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 ; int randomNumber; /* <<---------------------- declare here -------------------- */ out.println("Welcome to rock/paper/scissors!"); out.println("Which object would you like to choose?"); input = myScanner.findInLine(".").charAt(0); /* <<------------------- shift this here --------------------*/ do {out.println("Invalid input.Please try again."); } while ((input != 'R') || (input != 'r') || (input != 'P') || (input != 'P') || (input !='S') || (input != 's')); if ((input == 'R') || (input == 'r')) { //input = Rock; /* <<---------------- i see no reason why you want to assign input here ---------- */ 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; } } } }
-
- 12-25-2010, 01:17 PM #5
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Cannot find symbol variable Keyboard...
By Alnegar in forum New To JavaReplies: 6Last Post: 10-30-2010, 05:39 PM -
Java cannot find symbol- variable img
By crutchfieldj in forum New To JavaReplies: 3Last Post: 04-13-2010, 10:47 PM -
Cannot find symbol variable - Why? I can.. ^^
By Mattedatten in forum New To JavaReplies: 4Last Post: 03-08-2010, 07:07 PM -
Cannot find symbol variable pD! I cant fix it!!!
By Addez in forum New To JavaReplies: 2Last Post: 09-17-2009, 08:32 PM -
Cannot find symbol variable yourScore
By Addez in forum New To JavaReplies: 4Last Post: 08-17-2009, 10:48 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks