Results 1 to 3 of 3
Thread: LOOPing for Biggner
- 10-08-2011, 05:16 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 16
- Rep Power
- 0
LOOPing for Biggner
can you help me with this problem ...
example:
its just an example .... im stuck with that .. that how i can make that if i enter Y , 5 times it will show Customer 5 and then add the price ...====WELCOME to our REStaurant====
CODE=== Name=== PRICE
...1.===.Chicken ====$5
...2.===.burger=== ==$2
...3.===.Hotdog==== $3
What is your order sir ?[Enter the Code]: 1
Your order is: Chicken
//if i enter a code that dont have in the menu .. it will ask again for the code
Enter Quantity: 1
Do you want to enter again? (y/n) :
//if i enter Y it will loop again ...
//if i enter N it will show the receipt
===RECEIPT===
customer 1: $5
customer 2: $6
...............------
...............$11 // all his order will be add ...
-
Re: LOOPing for Biggner
First please show us your attempt, any attempt, to solve it. Let us know if your code shows any errors or any misbehaviors.
- 10-08-2011, 06:09 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 16
- Rep Power
- 0
Re: LOOPing for Biggner
Here it is ..
i want to loop that if the user enter Y , then it will loop for another customer , but im stuck ... i cant do it ..Java Code:import java.io.*; public class Ticket { public static BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); public static void main(String args [])throws Exception { // First declare your constants double BURGER = 1; double FRIES = 2; double COKE = 3; // Display the list of shows and prices to the user System.out.println("Menu:"); System.out.println("1. Burger $1.99"); System.out.println("2. Fries $1.69"); System.out.println("3. Coke $1.49"); // Prompt for and read in the number of the show int orderNumber = 0; int orderAmount = 0; double price = 0; String YN = ""; String error = ""; do { System.out.print("Enter desired item: "); orderNumber = Integer.parseInt(input.readLine()); // Prompt for and read in the number of the item if(orderNumber != 99) { System.out.print("How many would you like?: "); orderAmount =Integer.parseInt(input.readLine()); } // Use a switch statement to determine what price to use switch (orderNumber) { case 1: price += BURGER * orderAmount; break; case 2: price += FRIES * orderAmount; break; case 3: price += COKE * orderAmount; default: System.out.print("Sorry Wrong Code"); break; } System.out.print("do you want To order again ? (y/n)"); YN = input.readLine(); if(YN.equalsIgnoreCase("n")) { double total = price; System.out.println("Total: "+ total); } else if(YN.equalsIgnoreCase("y")) { } else { System.out.println("Invalid entry has occured, would you like to try again? Enter Y or N"); YN = input.readLine(); if(YN.equalsIgnoreCase("N")) { double subtotal = price; System.out.println("Subtotal:"+ subtotal); } if(YN.equalsIgnoreCase("Y")) { } } } while(YN.equalsIgnoreCase("y")); } }



Similar Threads
-
Problem with looping
By jarredh4 in forum New To JavaReplies: 2Last Post: 02-16-2011, 04:56 AM -
Looping
By Dean29126 in forum New To JavaReplies: 3Last Post: 09-08-2010, 02:01 PM -
Help with While and For Looping
By gmoney8316 in forum New To JavaReplies: 2Last Post: 03-03-2010, 10:54 PM -
looping and filtering
By javafanatic in forum New To JavaReplies: 14Last Post: 02-09-2010, 09:48 AM -
Looping Help Please
By JonnySnip3r in forum New To JavaReplies: 5Last Post: 01-31-2010, 05:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks