Results 1 to 3 of 3
  1. #1
    LogicBrix is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Question LOOPing for Biggner

    can you help me with this problem ...

    example:

    ====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 ...
    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 ...

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default 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.

  3. #3
    LogicBrix is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Default Re: LOOPing for Biggner

    Here it is ..

    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"));
    
    } 
    }
    i want to loop that if the user enter Y , then it will loop for another customer , but im stuck ... i cant do it ..

Similar Threads

  1. Problem with looping
    By jarredh4 in forum New To Java
    Replies: 2
    Last Post: 02-16-2011, 05:56 AM
  2. Looping
    By Dean29126 in forum New To Java
    Replies: 3
    Last Post: 09-08-2010, 03:01 PM
  3. Help with While and For Looping
    By gmoney8316 in forum New To Java
    Replies: 2
    Last Post: 03-03-2010, 11:54 PM
  4. looping and filtering
    By javafanatic in forum New To Java
    Replies: 14
    Last Post: 02-09-2010, 10:48 AM
  5. Looping Help Please
    By JonnySnip3r in forum New To Java
    Replies: 5
    Last Post: 01-31-2010, 06:57 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
  •