Results 1 to 2 of 2
  1. #1
    lifeturn is offline Member
    Join Date
    Feb 2008
    Posts
    1
    Rep Power
    0

    Default need help with program im lost

    /* Change this program so that instead of displaying the menu again for each
    * selection, it will display the item and its price:
    * for example, if the user selects an H, the screen will show
    * Hamburger $2.99 and the subtotal
    * It will keep doing this until the total is selected.
    */


    /**
    * @(#)Hamburger.java
    *
    * Hamburger application
    *
    * @Vlad
    * @version 1.00 2008/2/12
    */
    /* Change this program so that instead of displaying the menu again for each
    * selection, it will display the item and its price:
    * for example, if the user selects an H, the screen will show
    * Hamburger $2.99 and the subtotal
    * It will keep doing this until the total is selected.
    */

    import java.util.Scanner;

    public class Hamburger {

    public static void main(String[] args) {
    final double TAX_RATE = 0.0825; // 8.25%

    char Selection;
    double price;
    double food;

    double subtotal;
    double tax;
    double total;

    subtotal = 0.00;
    Selection = DisplayMenu(); // Get the FIRST entry from the user
    while (Selection != 'T')
    {
    if (Selection == 'H')
    food = Hamburger
    price = 2.99;

    else if (Selection == 'C')
    food = Cheeseburger
    price = 3.49;
    else if (Selection == 'S')
    food = Soda
    price = 1.75;
    else if (Selection == 'F')
    food = fries
    price = 1.35;
    else
    food = no food selected
    price = 0.00; // default if no condition above is satisfied

    subtotal += price;
    System.out.printf ("\nFood = $%.2f\n", food);
    System.out.printf ("\nSubtotal = $%.2f\n", subtotal);
    Selection = DisplayMenu(); // Get the NEXT entry from the user
    }
    // T was selected, display the tax and the total
    tax = subtotal * TAX_RATE;
    total = subtotal + tax;
    System.out.printf ("\n"\nFood = $%.2f\n", food);
    System.out.printf ("\n\nSubtotal = %.2f\n", subtotal);
    System.out.printf ( " Tax = %.2f\n", tax);
    System.out.printf ( " Total = %.2f\n", total);
    }

    public static char DisplayMenu()
    {
    Scanner input = new Scanner(System.in);
    String InputLine;
    char FirstCharOnLine;

    System.out.println ("H = hamburger $2.99");
    System.out.println ("C = cheese burger $3.49");
    System.out.println ("S = soda $1.75");
    System.out.println ("F = fries $1.35");
    System.out.println ("T = total");
    System.out.print ("Enter selection: ");
    InputLine = input.nextLine();
    InputLine = InputLine.toUpperCase();
    FirstCharOnLine = InputLine.charAt(0);
    return FirstCharOnLine;
    }
    }

    can someone explain how i can finish it
    i believe i have to creat another command that names wat u bought instead of going back to menu
    and return should be directed to it

  2. #2
    jayant3001's Avatar
    jayant3001 is offline Member
    Join Date
    Oct 2008
    Posts
    22
    Rep Power
    0

    Default

    Java Code:
    import java.util.Scanner;
    public class Hamburger {
    
    public static void main(String[] args) {
    final double TAX_RATE = 0.0825;	// 8.25%
    
    char Selection;
    double price;
    String food = "";
    
    double subtotal;
    double tax;
    double total;
    
    subtotal = 0.00;
    Selection = DisplayMenu();	// Get the FIRST entry from the user
    while (Selection != 'T')
    {
    if (Selection == 'H')
    {
    food = "Hamburger";
    price = 2.99;
    }
    else if (Selection == 'C')
    {
    food = "Cheeseburger";
    price = 3.49;
    }
    else if (Selection == 'S')
    {
    food = "Soda";
    price = 1.75;
    }
    else if (Selection == 'F')
    {
    food = "fries";
    price = 1.35;
    }
    else
    {
    food = "no food selected";
    price = 0.00;	// default if no condition above is satisfied
    }
    
    subtotal += price;
    System.out.println("Food = " + food);
    System.out.println("Subtotal = "+ subtotal);
    Selection = DisplayMenu();	// Get the NEXT entry from the user
    }
    // T was selected, display the tax and the total
    tax = subtotal * TAX_RATE;
    total = subtotal + tax;
    System.out.println("Food ="+ food);
    System.out.println("Subtotal = "+ subtotal);
    System.out.println( " Tax = "+tax);
    System.out.println( " Total = "+ total);
    }
    
    public static char DisplayMenu()
    {
    Scanner input = new Scanner(System.in);
    String InputLine;
    char FirstCharOnLine;
    
    System.out.println ("H = hamburger $2.99");
    System.out.println ("C = cheese burger $3.49");
    System.out.println ("S = soda $1.75");
    System.out.println ("F = fries $1.35");
    System.out.println ("T = total");
    System.out.print ("Enter selection: ");
    InputLine = input.nextLine();
    InputLine = InputLine.toUpperCase();
    FirstCharOnLine = InputLine.charAt(0);
    return FirstCharOnLine;
    }
    }

Similar Threads

  1. Lost my javadocs
    By orchid in forum Eclipse
    Replies: 3
    Last Post: 04-30-2008, 09:45 PM
  2. A little lost with for loops and making a design
    By LinxuS in forum New To Java
    Replies: 5
    Last Post: 01-22-2008, 09:05 AM
  3. Absolutely Lost
    By Lehane_9 in forum New To Java
    Replies: 2
    Last Post: 12-03-2007, 06:25 PM
  4. Help Needed - I'm so lost
    By adlb1300 in forum New To Java
    Replies: 3
    Last Post: 11-14-2007, 01:54 AM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 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
  •