Jump to content

How do i store prices for food on a menu?

airfrog19
Go to solution Solved by Nineshadow,

So i need to create another variable for the price of each food?

You already have them :

 

     double GoodBurgers = 7.75;
     double GoodSalads = 7.00;
     double Sodas = 2.00;
     double KidsMeals = 3.00;
 
Just change
 
subtotal = subtotal + GoodBurger/GoodSalad/etc. ( not the doubles I've just listed)
to :
subtotal  = subtotal + GoodBurgers/GoodSalads/etc. ( the variables in which you store the price for each food)
 
Then print it at the end.(choice == 5)

I'm having trouble implementing prices for my menu program. At the end of the loop it just prints out the food i ordered, but doesn't print out the prices. How do i do this ?

This is what i have: 

 

package project.pkg1;
import java.util.Scanner;
import java.text.DecimalFormat;
 
public class Project1 {
 
 
    public static void main(String[] args) {
     int choice = 0;
     boolean doneOrdering = false;
     String order;
     Scanner Keyboard = new Scanner(System.in);
     DecimalFormat moneyFormat = new DecimalFormat("$#,###.00");
     
     
     double num, GoodBurger = 0, GoodSalad = 0, Soda = 0, KidsMeal = 0;
     double GoodBurgers = 7.75;
     double GoodSalads = 7.00;
     double Sodas = 2.00;
     double KidsMeals = 3.00;
     double tax;
     double subtotal = 0, total;
     final double salestax = 0.875;
     
     
     System.out.println("Welcome to Good Burger!");
     System.out.println("=======================");
     System.out.println("Place your orders and type 'Finish' when you are done");
     System.out.println("--------------------------------------------------------");
    
    
     System.out.println("1. GoodBurger $7.75");
     System.out.println("2. GoodSalad $ 7.00");
     System.out.println("3. Soda $2.00");
     System.out.println("4. KidsMeal $3.00 \n");
     System.out.println("What would you like? \n");
    
     while(!doneOrdering){
         choice = Keyboard.nextInt();
         if( choice == 1){
             System.out.println("GoodBurger");
             subtotal = subtotal + GoodBurger;
         }
         else if( choice == 2){
             System.out.println("Good Salad");
             subtotal= subtotal + GoodSalad;
         }    
         else if( choice == 3){
             System.out.println("Soda");
             subtotal= subtotal + Soda;             
         } 
         else if( choice == 4){
             System.out.println("KidsMeal");
             subtotal = subtotal + KidsMeal;
         }
         else if( choice == 5){
             doneOrdering = true;
         }
         else{
             System.out.println("Invalid");
         }
          
     }  
Link to comment
Share on other sites

Link to post
Share on other sites

It doesn't print out the price,pretty obvious.

(+)You could try printing the price of each food when you chose it(if you want), I haven't done java in a long time but it should be like this : 

 

syso("<foodname> " + <foodpricevariable>);    <- syso is just a shortened form for System.out.printl in Eclipse , you need to write it full though.

 

 

Also change the subtotal thing to:

subtotal += GoodBurgers/GoodSalads/Sodas/KidsMeals ( the variable in which you store the price of a certain food type).

 

Then, at the end (choice == 5), also print the subtotal variable.

 

else if( choice == 5){
             doneOrdering = true;
             syso("Total : " + subtotal);
         }

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

It doesn't print out the price.Simply.

You could try printing the price of each food when you chose it, I haven't done java in a long time but it should be like this : 

how do i do calculate the subtotal?

Link to comment
Share on other sites

Link to post
Share on other sites

how do i do calculate the subtotal?

Read my updated post.

You're already calculating it.

Wait no...Time to update my first post again.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Read my updated post.

You're already calculating it.

So i need to create another variable for the price of each food?

And where would i put syso("<foodname> " + <foodpricevariable>); ? In the beginning?

Link to comment
Share on other sites

Link to post
Share on other sites

So i need to create another variable for the price of each food?

You already have them :

 

     double GoodBurgers = 7.75;
     double GoodSalads = 7.00;
     double Sodas = 2.00;
     double KidsMeals = 3.00;
 
Just change
 
subtotal = subtotal + GoodBurger/GoodSalad/etc. ( not the doubles I've just listed)
to :
subtotal  = subtotal + GoodBurgers/GoodSalads/etc. ( the variables in which you store the price for each food)
 
Then print it at the end.(choice == 5)

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

 

You already have them :

 

     double GoodBurgers = 7.75;
     double GoodSalads = 7.00;
     double Sodas = 2.00;
     double KidsMeals = 3.00;
 
Just change
 
subtotal = subtotal + GoodBurger/GoodSalad/etc. ( not the doubles I've just listed)
to :
subtotal  = subtotal + GoodBurgers/GoodSalads/etc. ( the variables in which you store the price for each food)
 
Then print it at the end.(choice == 5)

 

Ok got it. Just one more question: Once i get get all the prices, i have to print out a receipt of what i ordered. Do you know how to do that. I know it has something to do with Arrays. 

Link to comment
Share on other sites

Link to post
Share on other sites

Ok got it. Just one more question: Once i get get all the prices, i have to print out a receipt of what i ordered. Do you know how to do that. I know it has something to do with Arrays. 

You're already printing the name of the food (and the price of it if you did as I said) each time you order it.

If you have, let's say, 2 burgers, and want to print : 2 x Burgers : <price>

Then you need to change it a little bit.Create counter(s) for the amount of times you order each type of  food, remove all the printing in the first 4 choices.

You already have counters for the amount of times you order a food :

 

     double GoodBurger = 0, GoodSalad = 0, Soda = 0, KidsMeal = 0;   <-These are counters

 

Change each of the first 4 choices into this :

 

if (choice==<whatever>) {

<counter>++;

subtotal += <foodpricevariable>;

}

 

Then, at choice == 5 :

 

if(<counter>) syso(<counter> + " x <food name> : " + <counter> * <foodpricevariable>)

 

Then apply it for each of the food types.

Then at the end print the total, like you're already doing.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

You're already printing the name of the food (and the price of it if you did as I said) each time you order it.

If you have, let's say, 2 burgers, and want to print : 2 x Burgers : <price>

Then you need to change it a little bit.Create counter(s) for the amount of times you order each type of  food, remove all the printing in the first 4 choices.

You already have counters for the amount of times you order a food :

 

     double GoodBurger = 0, GoodSalad = 0, Soda = 0, KidsMeal = 0;   <-These are counters

 

Change each of the first 4 choices into this :

 

if (choice==<whatever>) {

<counter>++;

subtotal += <foodpricevariable>;

}

 

Then, at choice == 5 :

 

if(<counter>) syso(<counter> + " x <food name> : " + <counter> * <foodpricevariable>)

 

Then apply it for each of the food types.

Then at the end print the total, like you're already doing.

is adding tip the same thing?

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×