Results 1 to 15 of 15
  1. #1
    MyztikGecko is offline Member
    Join Date
    Aug 2015
    Posts
    8
    Rep Power
    0

    Default Help with coding errors

    I am having a problem figuring this out. I am not able to get the last method to work. If there is an easier way of putting this together, please advise; I suck at programming to begin with.

    Java Code:
    import java.util.Scanner; 
    import java.text.DecimalFormat; 
     
     
    // Programming Assingment 7 (Pass7)
    // Movie Theater Prices
       
    public class BockenstedtPass7
    
    {
    //Theater Number
    //Number of Adult Tickets
    //Number of Child Tickets
    //Theater 1: Adult (9.50)/Child 6.00)
    //Theater 2: Adult (12.50)/Child (7.50)
    //Run loop using sentinel -999
    
       static Scanner scan = new Scanner(System.in);
       DecimalFormat formatter = new DecimalFormat("##0.00");
       static int theater;
       static int adult;
       static int child;
       static double outcome;
       static double outcomeTwo;
       static double grand;
       
       
             
       public static void getTheater()
       {
          System.out.print("Enter Theater Number:");
          
          while (theater != -999)
          {
             theater = scan.nextInt();
             if (theater == 1)
             {
                getAdult();
             }
             if (theater == 2)
             {
                getAdult();
             }
          }
       }
       
       
       public static void getAdult()
       {
          System.out.print("Adult Tickets:");
          while (theater != -999)
          {
             adult = scan.nextInt();
             if (theater == 1)
             {       
                getChild();
             }
             if (theater == 2)
             {  
                getChild();
             }
          }
       }
       
       public static void getChild()
       {
          System.out.print("Child Tickets:");
          while (theater != -999)
          {
             child = scan.nextInt();
             if (theater == 1)
             {       
                getOutcome();
             }
             if (theater == 2)
             {  
                getOutcomeTwo();
             } 
          }
    }
       public static void getOutcome()
       {
          System.out.println("Theater Number: " +theater);
          System.out.println("  Adult Tickets: " +adult);
          System.out.println("  Child Tickets: " +child);
          double adultPriceOne = 9.50;
          double childPriceOne = 6.00;
          double theaterOne = (adult * adultPriceOne) + (child * childPriceOne);
          if (theater == 1)
          {
             System.out.printf("Amount (total): $%.2f", +theaterOne);
             System.out.println("\n");
             getTheater();
          }
       }
       public static void getOutcomeTwo()
       {
          System.out.println("Theater Number: " +theater);
          System.out.println("  Adult Tickets: " +adult);
          System.out.println("  Child Tickets: " +child);
          double adultPriceTwo = 12.50;
          double childPriceTwo = 7.50;
          double theaterTwo = (adult * adultPriceTwo) + (child * childPriceTwo);   
          if (theater == 2)
          {
             System.out.printf("Amount (total): $%.2f", +theaterTwo);
             getGrand();
          }
       }
       public static void getGrand()
       {
          Scanner grand = new Scanner(System.in);
          double totalOne = grand.nextDouble(getOutcome());
          double totalTwo = grand.nextDouble(getOutcomeTwo());
          double grandTotal = (totalOne + totalTwo);
          System.out.println("\n");
          System.out.printf("Total Amount: $%.2f", +grandTotal);
          System.exit(0);
       }
       
       
       public static void main(String[] args)
       {
          getTheater();
          getAdult();
          getChild();
          getOutcome();
          getOutcomeTwo();
          getGrand();
       }
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Help with coding errors

    What are you trying to do? I notice that you read both adult and child from the console and then still check the value of theater. You can also combine your statements.

    Java Code:
    if(theater == 1 || theater== 2) {
       // do something
    }
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Help with coding errors

    I am not able to get the last method to work.
    Please explain.
    Which method are you referring to? The last one I see in the above code is main()
    What is the method you are having problems with supposed to do?
    What does it do now?

    If there are error messages, please copy the full text and paste it here.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    399
    Rep Power
    6

    Default Re: Help with coding errors

    I have a feeling that the OP wants to enter the sold tickets for adults and kids for 2 theaters and then multiply out the total sales. Here are my first thoughts:

    1. You are lining up most methods in the sense that each methods calls the next method in the calculation, but then you call them a second time in the main method. That might be a potential source for hick-ups. I think it would easier if you have each method return a value and scratch all the " internal line-up".
    2. Since you have theater specific prices you have to store visitor quantities separately for each theater, which you solve by the " internal line up" of methods. I would suggest that you put all values in an arraylist and then multiply out at the end.

  5. #5
    MyztikGecko is offline Member
    Join Date
    Aug 2015
    Posts
    8
    Rep Power
    0

    Default Re: Help with coding errors

    Quote Originally Posted by jim829 View Post
    What are you trying to do? I notice that you read both adult and child from the console and then still check the value of theater. You can also combine your statements.

    Java Code:
    if(theater == 1 || theater== 2) {
       // do something
    }
    Regards,
    Jim
    If there is a way to simplify the code, that would be helpful. I have a feeling that I should be using the switch or else if commands

  6. #6
    MyztikGecko is offline Member
    Join Date
    Aug 2015
    Posts
    8
    Rep Power
    0

    Default Re: Help with coding errors

    I am referring to the getGrand() method. It needs to calculate the sum of getOutcome and getOutcomeTwo.

  7. #7
    MyztikGecko is offline Member
    Join Date
    Aug 2015
    Posts
    8
    Rep Power
    0

    Default Re: Help with coding errors

    With the way that I have it listed the only errors that I am getting are 'void' type not allowed on lines 113 and 114

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Help with coding errors

    'void' type not allowed on lines 113 and 114
    There is no value returned by the methods called on those lines. The methods are defined as void.
    You can not assign void to a variable.
    You need to change the methods' definitions from void to the data type that you want them to return.
    Then you can assign what they return to a variable as in lines 113 and 114.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    MyztikGecko is offline Member
    Join Date
    Aug 2015
    Posts
    8
    Rep Power
    0

    Default Re: Help with coding errors

    Quote Originally Posted by Norm View Post
    There is no value returned by the methods called on those lines. The methods are defined as void.
    You can not assign void to a variable.
    You need to change the methods' definitions from void to the data type that you want them to return.
    Then you can assign what they return to a variable as in lines 113 and 114.
    could you show me how to do that. I have tried to change both getOutcome and getOutcomeTwo to be double and it then asks for a return.

  10. #10
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    399
    Rep Power
    6

    Default Re: Help with coding errors

    Quote Originally Posted by MyztikGecko View Post
    If there is a way to simplify the code, that would be helpful. I have a feeling that I should be using the switch or else if commands
    I would ask in the beginning how many theaters? And then use a nested for loop: how many adult tickets in theater1? How many kids tickets in theater1, then store all values in an array.

  11. #11
    MyztikGecko is offline Member
    Join Date
    Aug 2015
    Posts
    8
    Rep Power
    0

    Default Re: Help with coding errors

    Quote Originally Posted by benji2505 View Post
    I would ask in the beginning how many theaters? And then use a nested for loop: how many adult tickets in theater1? How many kids tickets in theater1, then store all values in an array.
    could you show me an example of how that would look?

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Help with coding errors

    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    MyztikGecko is offline Member
    Join Date
    Aug 2015
    Posts
    8
    Rep Power
    0

    Default Re: Help with coding errors

    I have changed up the code drastically; after watching a couple videos. Is this easier to follow, or I am still way off? I am still getting errors but now it is 'error: reached end of file while parsing'
    Java Code:
    import java.util.Scanner; 
    import java.text.DecimalFormat; 
     
     
    // Programming Assingment 7 (Pass7)
    // Movie Theater Prices
       
    public class BockenstedtTheater
    
    {
    //Theater Number
    //Number of Adult Tickets
    //Number of Child Tickets
    //Theater 1: Adult (9.50)/Child 6.00)
    //Theater 2: Adult (12.50)/Child (7.50)
    //Run loop using sentinel -999
    
       static Scanner scan = new Scanner(System.in);
       DecimalFormat formatter = new DecimalFormat("##0.00");
       static int theater;
       static int adult;
       static int child;
       static double outcome;
       static double outcomeTwo;
       static double grand;
       
       //Start program
       public static void main(String[] args)
       {
       while (theater != -999)
       {
       System.out.println("Enter Theater Number: " +theater);
       for(int theater=1;theater<=2;theater++)
       {
          theater = scan.nextInt();
          {
          System.out.print("Adult Tickets:");
          adult = scan.nextInt();
          System.out.print("Child Tickets:");
          child = scan.nextInt();
          if (theater == 1 || theater == 2)
          {
          System.out.println("Theater Number: " +theater);
          System.out.println("  Adult Tickets: " +adult);
          System.out.println("  Child Tickets: " +child);
          double adultPriceOne = 9.50;
          double childPriceOne = 6.00;
          double outcome = (adult * adultPriceOne) + (child * childPriceOne);
          System.out.printf("Amount (total): $%.2f", +outcome);
             System.out.println("\n");
          }
          else
          {
          System.out.println("Theater Number: " +theater);
          System.out.println("  Adult Tickets: " +adult);
          System.out.println("  Child Tickets: " +child);
          double adultPriceTwo = 12.50;
          double childPriceTwo = 7.50;
          double outcomeTwo = (adult * adultPriceTwo) + (child * childPriceTwo);
          System.out.printf("Amount (total): $%.2f", +theaterTwo);
          }
          double grand = (outcome + outcomeTwo);
          System.out.println("\n");
          System.out.printf("Total Amount: $%.2f", +grand);
          System.exit(0);

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Help with coding errors

    'error: reached end of file while parsing'
    Check that there are matching }s for all {s. There should always be a } at the end of a class's definition.
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Help with coding errors

    It makes no sense to use theater as the target of a for loop and to also prompt the user for theater. Since this is apparently for a class I recommend you discuss with your classmates and/or your instructor. You may also want to supplement your class by reading the Java tutorials. There is a link in my signature.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. help with this coding
    By dannyboi in forum New To Java
    Replies: 2
    Last Post: 12-17-2012, 08:00 AM
  2. Replies: 4
    Last Post: 01-04-2011, 12:36 AM
  3. Replies: 4
    Last Post: 10-25-2010, 03:49 PM
  4. Replies: 3
    Last Post: 03-08-2009, 01:51 AM
  5. coding help
    By accies76 in forum New To Java
    Replies: 5
    Last Post: 11-12-2008, 08:15 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
  •