PLZ Need some help on the 2nd part of this question...Someone please help !!!!

write an application that displays a menue of three items in a restaurant as follows: 1.Cheeseburger 4.99 2.Pepsi 2.00 3.Chips 0.75 prompt the user to choose an item using the number (1,2,or 3) that corresponds to the item, or to enter 0 to quit the application.after the user makes the first selection, if the choice is 0, display a bill of $0.otherwise,display the menu again.the user should respond to this prompt with another item number to order or 0 to quit.if the user types0,display the cost of the single requested item.if the user types 1,2 or 3 add the cost of the second item to the first, and then display the menu a third time.if the user types 0 to quit,display the total cost of the two items;otherwise,display the total for all three selections.save the file as FastFood.java

B. modify the application in Exercise above so that if the user makes a menu selection he or she has already made, ignore the selection-that is,do not add a second price for the same item to the total.the user is still allowed only three entries.save the file as FastFood2.java

View Answers

September 22, 2011 at 12:46 PM

import java.util.Scanner;
 class FastFood
{
  public static double check1 = 0.0;
  public static double check2 = 0.0;
  public static double check3 = 0.0;
    public static double order()
  {
    int selection;
     System.out.println("(1) Cheeseburger 4.99");
     System.out.println("(2) Pepsi        2.00");
     System.out.println("(3) Chips        0.75");

     Scanner input = new Scanner(System.in);

     System.out.println("\nWhich item would you like to order?");
     selection = input.nextInt();

     if(selection == 1)
     {  
        check1 = 4.99;  
        return 4.99;
     }  
     else if (selection == 2)
     { 
       check2 = 2.00;
       return 2.00;
     }  
     else if (selection == 3)
     { 
       check3 = 0.75;  
        return 0.75;
     }
     else
       return 0;
  }
}
public class FastFood2 {


  public static void main(String[] args)
  {
      FastFood food=new FastFood();
    double foodTotal = 0.0;
     double item1 = 0.0;
     double item2 = 0.0;
     double item3 = 0.0;

     item1 = food.order();
     if ((item1 > 0) && (food.check1 != 4.99) || (food.check2 != 2.00) || (food.check3 != 0.75))
       item2 = food.order();
     if ((item2 > 0) && (food.check1 != 4.99) || (food.check2 != 2.00) || (food.check3 != 0.75))
       item3 = food.order();

     foodTotal = food.check1 + food.check2 + food.check3;
     System.out.println("Total Bill is: $" + foodTotal);
       }

}









Related Tutorials/Questions & Answers: