Results 1 to 5 of 5
  1. #1
    ironman_777 is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default 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;
    }
    }
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    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;
                            }
                    }
            }
    }

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by JavaHater View Post
    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.
    Excellent post. Thanks!
    1+ rep

  5. #5
    ironman_777 is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default

    Thank you so much! That fixed my problem with the variable declarations, but now it says that the variable INPUT might not have been initialized at the "while" part of the "do" statement. Is this an easy fix as well? Thanks
    Last edited by ironman_777; 12-25-2010 at 02:26 PM.

Similar Threads

  1. Cannot find symbol variable Keyboard...
    By Alnegar in forum New To Java
    Replies: 6
    Last Post: 10-30-2010, 06:39 PM
  2. Java cannot find symbol- variable img
    By crutchfieldj in forum New To Java
    Replies: 3
    Last Post: 04-13-2010, 11:47 PM
  3. Cannot find symbol variable - Why? I can.. ^^
    By Mattedatten in forum New To Java
    Replies: 4
    Last Post: 03-08-2010, 08:07 PM
  4. Cannot find symbol variable pD! I cant fix it!!!
    By Addez in forum New To Java
    Replies: 2
    Last Post: 09-17-2009, 09:32 PM
  5. Cannot find symbol variable yourScore
    By Addez in forum New To Java
    Replies: 4
    Last Post: 08-17-2009, 11:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •