Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. a. Write an application that displays a menu of three items in a restaurant a

ID: 3904915 • Letter: 1

Question

1. a. Write an application that displays a menu of three items in a restaurant as follows: (1) Cheeseburger 3.99 (2) Pepsi 1.50 (3) Chips 1.00 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 types 0, 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.

Explanation / Answer

import java.util.*;

class FastFood
{
public static void main (String[] args)
{
  Scanner input = new Scanner(System.in);
  int option ;
  double bill = 0;
  
  
  do
  {
  System.out.println(" (1) Cheeseburger 3.99 (2) Pepsi 1.50 (3) Chips 1.00");
  System.out.println("Choose an item <1,2 or 3> or enter 0 to quit");
  option = input.nextInt();

  
  switch(option)
  {
   case 0: System.out.println("Bill : $"+bill);
    System.exit(0);
   case 1: bill = bill + 3.99;
    break;
   case 2: bill = bill + 1.50;
    break;
   case 3: bill = bill + 1.00;
    break;
   default:
    break;
    
  }
  }while(option != 0);
  
  System.out.println("Bill : $"+bill);
}
}

Output:

(1) Cheeseburger 3.99
(2) Pepsi 1.50
(3) Chips 1.00
Choose an item <1,2 or 3> or enter 0 to quit

(1) Cheeseburger 3.99
(2) Pepsi 1.50
(3) Chips 1.00
Choose an item <1,2 or 3> or enter 0 to quit

(1) Cheeseburger 3.99
(2) Pepsi 1.50
(3) Chips 1.00
Choose an item <1,2 or 3> or enter 0 to quit

(1) Cheeseburger 3.99
(2) Pepsi 1.50
(3) Chips 1.00
Choose an item <1,2 or 3> or enter 0 to quit
Bill : $6.49

Do ask if any doubt. Please upvote.