Page 1 of 2 12 LastLast
Results 1 to 20 of 27

Thread: Help!!!!

  1. #1
    Java_Newb is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Question Help!!!!

    Hey I'm trying to write a program for a movie theatre that will not only display movie ticket prices but also analyze the number of tickets purchased and calculate the total price. I'm stuck on trying to prompt the user on how many of a specific type of ticket. What I have so far is:

    System.out.print("How many Matinee tickets would you like to buy");
    Double Matinee;
    Scanner Keyboard;
    Keyboard = new scanner (system.in);
    Matinee = scan.nextInt();

    Also at the very top of my program I have:

    import java.util.Scanner;

    Any advice would be greatly appreciated!

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    It might be a good idea to post the code you are using and say whether or not it compiles. If you can't understand a compiler message then post the complete message and that will provide the basis for a concrete question.

    -----

    Be careful with case. Java variables begin with a lowercase letter and classes with an upper case one: so matinee and Scanner. It's also a good idea for variables to be chosen so that they are as descriptive as possible. In this case numMatinee would be a good choice for a variable intended to represent the desired number of matinee tickets.

  3. #3
    Java_Newb is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default

    Thanks pbrockway2, well the code that I am using is listed below and it will not compile. Also I included the compiler message.

    import java.util.Scanner;

    public class Assignment2
    {
    public static void main (String[] args)
    {
    System.out.println ("Welcome to the Movie Theatre!");
    System.out.println ("The cost of movie tickets:");
    System.out.println ("Maitinee $5.00");
    System.out.println ("Normal $7.50");
    System.out.println ("Rush Hour $3.50");

    Scanner scan = new Scanner(System.in);

    System.out.print ("How many Maitinee tickets would you like to buy?");
    Double Maintnee;
    Scanner keyboard;
    Keyboard = new scanner (system.in);
    Maintinee = scan.nextInt();

    System.out.print ("How many NoKne.rmal tickets would you like to buy?");
    normal = scan.nextInt();

    System.out.print ("How many Rush Hour tickets would you like to buy?");
    RushHour = scan.nextInt();

    }

    }

    Assignment2.java:34: cannot find symbol
    symbol : variable Keyboard
    location: class Assignment2
    Keyboard = new scanner (system.in);
    ^
    Assignment2.java:34: cannot find symbol
    symbol : class scanner
    location: class Assignment2
    Keyboard = new scanner (system.in);
    ^
    Assignment2.java:34: cannot find symbol
    symbol : variable system
    location: class Assignment2
    Keyboard = new scanner (system.in);
    ^
    Assignment2.java:35: cannot find symbol
    symbol : variable Maintinee
    location: class Assignment2
    Maintinee = scan.nextInt();
    ^
    Assignment2.java:38: cannot find symbol
    symbol : variable normal
    location: class Assignment2
    normal = scan.nextInt();
    ^
    Assignment2.java:41: cannot find symbol
    symbol : variable RushHour
    location: class Assignment2
    RushHour = scan.nextInt();
    ^
    6 errors

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    Keyboard = new scanner (system.in);
    Where is the variable Keyboard defined? The compiler can't find its definition.
    The same problem for several other variables with the same error message.
    You need to define variables before using them.

    Assignment2.java:34: cannot find symbol
    symbol : class scanner
    Assignment2.java:34: cannot find symbol
    symbol : variable system
    Java is case sensitive. You must spell class names with the correct case. In both cases you need a S.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Remember that variables are (1) declared (2) initialised (given a value) (3) used. Typically all three happen for your variables in that order. ("used" occurs many times and includes giving the variable a new value). Compared with other languages Java is fussy about this.

    Java Code:
    int theAnswer; // declared
    theAnswer = 42; // initialised
    System.out.println("The answer is " + theAnswer); // used
    Sometimes steps (1) and (2) are combined:

    Java Code:
    int theAnswer = 42; // declared and initialised
    // etc
    "Cannot find symbol" usually means "you have forgotten to declare this" or "you have spelt this wrong". Later you will find it also means "you are using this method with the wrong arguments".

    So, ... make sure all of your variables/classes/methods are spelt correctly. For your own, you only need to be consistent, for any supplied by Java you don't have a choice. And make sure your variables are declared somewhere before they are used.

  6. #6
    Java_Newb is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default

    Ok, so I have tried another way of writing the first part of code for this program.

    double numMaitinee; //declared variable

    Scanner scan = new Scanner (System.in); // Creates object that reads input from the keyboard

    System.out.print ("How many Maitinee Tickets would you like to buy?"); //Prompt for user input
    numMaintinee = scan.nextDouble(); //

    System.out.println("You entered:" + numMaintinee);

    The error message I am getting now is,

    Assignment2.java:34: cannot find symbol
    symbol : variable numMaintinee
    location: class Assignment2
    numMaintinee = scan.nextDouble();
    ^
    Assignment2.java:36: cannot find symbol
    symbol : variable numMaintinee
    location: class Assignment2
    System.out.println("You entered:" + numMaintinee);
    ^
    2 errors


    Does this mean I did not properly declare what numMaintinee is?

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

    Default

    Let's see your actual code meaning where you declare the variables, whether they're declared inside of the method or outside and if outside whether they're static or not.

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Java Code:
    double [b][color=red]numMaitinee[/color][/b]; //declared variable
    
    Scanner scan = new Scanner (System.in); // Creates object that reads input from the keyboard
    
    System.out.print ("How many Maitinee Tickets would you like to buy?"); //Prompt for user input
    [b][color=red]numMaintinee[/color][/b] = scan.nextDouble(); //
    
    System.out.println("You entered:" + numMaintinee);
    Spelling mistake.

  9. #9
    Java_Newb is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default

    Ok so I fixed the spelling mistake and its not giving me an error, but its still not running the the prompt for users to enter how many tickets they want? This is what it is telling me now:

    Welcome to the Movie Theatre!
    The cost of movie tickets:
    Maitinee $5.00
    Normal $7.50
    Rush Hour $3.50
    Exception in thread "main" java.util.NoSuchElementException
    at java.util.Scanner.throwFor(Scanner.java:838)
    at java.util.Scanner.next(Scanner.java:1461)
    at java.util.Scanner.nextDouble(Scanner.java:2387)
    at Assignment2.main(Assignment2.java:34)
    How many Maitinee Tickets would you like to buy?

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default Re: Help!!!!

    Exception in thread "main" java.util.NoSuchElementException
    at java.util.Scanner.nextDouble(Scanner.java:2387)
    at Assignment2.main(Assignment2.java:34)
    The error occurs when your code calls the Scanner class's nextDouble method.
    Read the API doc for the Scanner class's nextDouble method. It explains what the problem under the Throws section near the bottom.

  11. #11
    Java_Newb is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default Re: Help!!!!

    So I checked out the API doc for the Scanner class and to be honest that did not make any sense so me? :/ But I'm also writing another program that uses the scanner class and it is giving me the same issue? Could it be something with my text editor or compiler?

  12. #12
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default Re: Help!!!!

    Let's pretend none of the previous posts exist and start fresh. Post your code. Post your error message(s). Indicate on which line the error occurs. If it is a runtime error then explain what your input is.

  13. #13
    Java_Newb is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default Re: Help!!!!

    Code:
    import java.util.Scanner;

    public class Assignment2
    {
    public static void main (String[] args)
    {
    System.out.println ("Welcome to the Movie Theatre!");
    System.out.println ("The cost of movie tickets:");
    System.out.println ("Maitinee $5.00");
    System.out.println ("Normal $7.50");
    System.out.println ("Rush Hour $3.50");


    Scanner scan = new Scanner (System.in);

    System.out.print ("How many Maitinee Tickets would you like to buy?");
    double numMaitinee;
    numMaitinee = scan.nextDouble();

    System.out.println("You entered:" + numMaitinee);

    }

    }

    Error message:

    Welcome to the Movie Theatre!
    The cost of movie tickets:
    Maitinee $5.00
    Normal $7.50
    Rush Hour $3.50
    Exception in thread "main" java.util.NoSuchElementException
    at java.util.Scanner.throwFor(Scanner.java:838)
    at java.util.Scanner.next(Scanner.java:1461)
    at java.util.Scanner.nextDouble(Scanner.java:2387)
    at Assignment2.main(Assignment2.java:34)

    How many Maitinee Tickets would you like to buy?

    The part that I am confused about is the program is not telling me that I have an error. Or this is not a normal error message as if I had a syntax error. I'm still a beginner so this could be a runtime error but I am not sure.

  14. #14
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default Re: Help!!!!

    Imagine I have a very bad lotto draw system: a box contains 3 ping-pong balls and I need to draw out 6 balls. What happens when I try to draw the 4th ball? There aren't any more balls left.

    What you are doing is similar. You are getting the Scanner to read something from input when there isn't anything there to read. Now you know what is wrong, you need to track down why.

  15. #15
    Java_Newb is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default Re: Help!!!!

    Hmmm ok I'm going to work on it tonight and see if I can knock the bug out of my program. Thank-you!!!

  16. #16
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default Re: Help!!!!

    How are you running the program? I just copied your code and it compiled and ran just fine for me.

  17. #17
    Java_Newb is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default Re: Help!!!!

    If you mean by how. It is java. If that is not the answer you are looking for I'm sorry.

  18. #18
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default Re: Help!!!!

    I mean how do you run the program and what input(s) do you give. Do you launch it from your IDE or from the command line? When do you give input? How do you give input (type it manually, read it from a text file, etc)?

  19. #19
    Java_Newb is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default Re: Help!!!!

    Well I run the program using text mate run&compiler. I give input after the Welcome and the prices and you type it in manually. Hope that helps.

  20. #20
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default Re: Help!!!!

    As I said I ran your program just fine from the command line. I am somewhat confused that you get the error before the print statement prompting for input.

Page 1 of 2 12 LastLast

Posting Permissions

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