Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: cannot find symbol variable lines 24, 25, 44, 45, 63, 64? Help!

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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
    Member goldest's Avatar
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    63
    Thanks
    1
    Thanked 12 Times in 10 Posts

    Default Re: cannot find symbol variable lines 24, 25, 44, 45, 63, 64? Help!

    Hi IronMan,

    Please post your code in
    // Your code goes here.
    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
    Java Is A Funny Language... Really!

    Sun: Java Coding Conventions

    Click on THANKS if you like the solution provided.
    Click on Star if you are really impressed with the solution.

  3. #3
    Member goldest's Avatar
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    63
    Thanks
    1
    Thanked 12 Times in 10 Posts

    Wink 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
    Java Is A Funny Language... Really!

    Sun: Java Coding Conventions

    Click on THANKS if you like the solution provided.
    Click on Star if you are really impressed with the solution.

Similar Threads

  1. Cannot find symbol?
    By stealthmonkey in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 10th, 2010, 10:02 PM
  2. cannot find symbol in reference variable
    By NPotter86 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 1st, 2010, 08:21 PM
  3. Help with Cannot Find Symbol Variable errors
    By skboone in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 20th, 2010, 10:52 AM
  4. cannot find symbol variable radius?
    By noobish in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 4th, 2009, 10:29 AM
  5. Replies: 5
    Last Post: September 19th, 2009, 06:48 AM