Results 1 to 2 of 2
  1. #1
    carrotcake is offline Member
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Default Having trouble looping & printing output

    Hi, I'm a college student in a beginning java class. For the program we had to write a program that could take orders and then calculate it using different methods. Here I only posted my main method and I'm having trouble because when I try to type in "n" for when it asks "Would you like another item?" it won't print out the output.

    (I don't know if you guys need me to post my other methods or not)

    main
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    displayIntro(); //displayIntro method call
    boolean quitMenu = true;
    while (quitMenu == true){

    //Declare variables
    int choice;
    int bookCount = 0;
    int musicCount = 0;
    int movieCount = 0;
    int bookChoice;
    int movieChoice;
    int musicChoice;

    double currBookPrice = 0;
    double currMoviePrice = 0;
    double currMusicPrice = 0;
    double finalSubtotal = 0;
    double finalTax = 0;
    double finalTotal = 0;
    double finalAverage = 0;


    Scanner input = new Scanner(System.in);



    double tax = setTax(); //setTax method call

    boolean retry = true;

    while (retry == true){

    choice = displayMenu(); //displayMenu method call
    if (choice == 1){
    bookCount++;
    currBookPrice += selectBook();
    }
    if (choice == 2){
    movieCount++;
    currMoviePrice += selectMovie();
    }
    if (choice == 3){
    musicCount++;
    currMusicPrice += selectMusic();
    }



    System.out.print("Would you like to choose another item (y/n)? ");
    String answer = input.next();
    if (answer.equalsIgnoreCase("n")) {
    retry = false;

    System.out.print("Order Summary: \n ");
    System.out.printf(bookCount + " Book(s) $%.2f\n", currBookPrice + " / Average $%.2f\n");
    System.out.printf(movieCount + " Movie(s) $%.2f\n", currMoviePrice + "/ Average $%.2f\n");
    System.out.printf(musicCount + " CD(s) $%.2f\n", currMusicPrice + "/ Average $%.2f \n");
    System.out.printf("Subtotal: $%.2f\n", finalSubtotal);
    System.out.printf("Tax: $%.2f\n", finalTax);
    System.out.printf("Total: $%.2f\n", finalTotal);
    System.out.printf("Average Cost Per Item: $%.2f", finalAverage);

    finalSubtotal = calculateSubtotal();
    finalTax = calculateTax();
    finalTotal = calculateTotal();
    finalAverage = finalTotal / (bookCount + movieCount + musicCount);

    break;
    }





    }

    System.out.print("Would you like to place another order (y/n)? ");
    String answer = input.next();
    if (answer.equalsIgnoreCase("n")) {
    quitMenu = false;
    break;
    }
    }

    }

  2. #2
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

Similar Threads

  1. Help with While and For Looping
    By gmoney8316 in forum New To Java
    Replies: 2
    Last Post: 03-03-2010, 10:54 PM
  2. Looping Help Please
    By JonnySnip3r in forum New To Java
    Replies: 5
    Last Post: 01-31-2010, 05:57 AM
  3. Having printing trouble
    By random0munky in forum New To Java
    Replies: 5
    Last Post: 12-07-2009, 09:27 PM
  4. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 11:44 PM
  5. Looping problem
    By Tanilo in forum New To Java
    Replies: 1
    Last Post: 08-01-2008, 06:34 AM

Posting Permissions

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