Results 1 to 2 of 2
- 04-03-2010, 05:58 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 1
- Rep Power
- 0
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;
}
}
}
- 04-04-2010, 05:37 AM #2
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
Similar Threads
-
Help with While and For Looping
By gmoney8316 in forum New To JavaReplies: 2Last Post: 03-03-2010, 10:54 PM -
Looping Help Please
By JonnySnip3r in forum New To JavaReplies: 5Last Post: 01-31-2010, 05:57 AM -
Having printing trouble
By random0munky in forum New To JavaReplies: 5Last Post: 12-07-2009, 09:27 PM -
Java, output string, getting correct output? HELP!
By computerboyo in forum New To JavaReplies: 2Last Post: 02-25-2009, 11:44 PM -
Looping problem
By Tanilo in forum New To JavaReplies: 1Last Post: 08-01-2008, 06:34 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks