Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27

Thread: Help!!!!

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

    Default Re: Help!!!!

    Yes that is the same problem I am facing? Thank you for verifying that my program at least runs.

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

    Default Re: Help!!!!

    Alright so I figured out the my compiler for text mate has an issue with compiling this specific code. But running it through terminal it runs but now I have another problem. It does not want to prompt the user with the second question? Here is my 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?");
    int numMaitinee;
    numMaitinee = scan.nextInt();

    System.out.print("You entered:" + numMaitinee + "Matinee tickets.");

    System.out.print ("How many Normal tickets would you like to buy?");
    int numNormal=scan.nextInt();

    System.out.print("You entered: " + numNormal + "Normal tickets.");

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

    System.out.print("You entered: " + numRush + "Rush Hour tickets.");

    //---------------------------------------------------------------------------
    // Calculation of Cost for Matinee, Normal, and Rush Hour
    //---------------------------------------------------------------------------

    double totMatinee;
    totMatinee = numMaitinee*(5.00);

    System.out.println ("The total cost for Matinee tickets:$ " + totMatinee);

    double totNormal;
    totNormal = numNormal*(7.50);

    System.out.println ("The total cost for Normal tickets:$ " + totNormal);

    double totRush;
    totRush = numRush*(3.50);

    System.out.println ("The total cost for Rush Hour tickets:$ " + totRush);

    double alltickets$;
    alltickets$ = totMatinee + totNormal + totRush;
    System.out.println ("The total cost for all tickets:$ " + alltickets$);

    double alltickets;
    alltickets = numMaitinee + numNormal + numRush;
    System.out.println ("The total number of tickets: " + alltickets);

    System.out.println ("The average cost per ticket for this purchase:$ " + (alltickets$/alltickets));
    }

    }

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

    Default Re: Help!!!!

    I really need to bookmark this so I don't have to keep explaining it. (no offense to the OP)

    The nextInt method does not consume an end-of-line (EOL). If you type 42[enter] then the nextInt method will only read the 42 and leave the EOL. The next time you call next or nextLine then it will read the empty String that exists before the EOL and return that. Quick and dirty solution is to add a call to nextLine after your call to nextInt.

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

    Default Re: Help!!!!

    I tried to add the call to next line after writing my first code but it was incorrect. This is the code I tried to write:

    numMatinee=scan.nextIntln();

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

    Default Re: Help!!!!

    There is no such method as nextIntln. You cannot call method that do not exist.
    Java Code:
    int value = scanner.nextInt();
    scanner.nextLine();
    That is what I meant.

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

    Default Re: Help!!!!

    Ok well I tried that with just my first part of code and now it won't let me compile it. :/ Maybe I miss understood your advice.

    Code:
    Int numMatinee;
    numMatinee=scan.nextInt();
    scanner.nextln(); //Error

    Error:

    Assignment2.java:43: cannot find symbol
    symbol : variable scanners
    location: class Assignment2
    scanners.nextln();
    ^
    1 error

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

    Default Re: Help!!!!

    Once again, you cannot call a method that does not exist. Read the API for the Scanner class. Compare you code with mine.

Page 2 of 2 FirstFirst 12

Posting Permissions

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