Results 1 to 2 of 2
Thread: need help with program im lost
- 02-12-2008, 11:54 PM #1
Member
- Join Date
- Feb 2008
- Posts
- 1
- Rep Power
- 0
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
- 10-28-2008, 07:09 PM #2
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
-
Lost my javadocs
By orchid in forum EclipseReplies: 3Last Post: 04-30-2008, 09:45 PM -
A little lost with for loops and making a design
By LinxuS in forum New To JavaReplies: 5Last Post: 01-22-2008, 09:05 AM -
Absolutely Lost
By Lehane_9 in forum New To JavaReplies: 2Last Post: 12-03-2007, 06:25 PM -
Help Needed - I'm so lost
By adlb1300 in forum New To JavaReplies: 3Last Post: 11-14-2007, 01:54 AM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks