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