Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-13-2008, 01:54 AM
Member
 
Join Date: Feb 2008
Posts: 1
lifeturn is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-28-2008, 09:09 PM
jayant3001's Avatar
Member
 
Join Date: Oct 2008
Posts: 22
jayant3001 is on a distinguished road
Send a message via Yahoo to jayant3001
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; } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lost my javadocs orchid Eclipse 3 04-30-2008 11:45 PM
A little lost with for loops and making a design LinxuS New To Java 5 01-22-2008 11:05 AM
Absolutely Lost Lehane_9 New To Java 2 12-03-2007 08:25 PM
Help Needed - I'm so lost adlb1300 New To Java 3 11-14-2007 03:54 AM
How to execute an External Program through Java program JavaBean Java Tips 0 10-04-2007 11:33 PM


All times are GMT +3. The time now is 11:24 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org