In: Computer Science
Question 1. Your task is to create a full program for a Restaurant of your choice. You will have the output appear at first saying Welcome to ______ Restaurant where the _____ will be whatever you name your restaurant
Today’s choices are 1.__________ 2._________ 3._______ 4.________
NOTE each _____ will say an item and its price for example pizza 2.99 Please choose 1 of the choices. In each case, as the user picks a choice It will calculate the total cost of the item based on a tax of 8.5%(multiply cost by 0.085) and add to original cost It will output what the user chose and the total cost for the bill in correct money format IF the user enters in something other than 1 through 4 it will say. INVALID CHOICE and the cost will be $0.00 It will then say. Thank You and have a nice day!
Hey , because no language specified I am using JAVA langauge to code it.
--------------------------------------------------------------------------------
file-name: Main.java --------------------------------- import java.util.Scanner; /* * We continuously loop through the menu and ask user to enter his choice. * If user enters the valid choice, that porder price is added to totalPrice ( and it is declared as static ) * And every time, customer places an order, it will show the current bill amount * * If the customer enters INVALID number, then we exit from the loop and show the total price * * If the user input is INVALID in the first iteration itself, then totalprice is shown as 0$. */ public class Main { static double totalPrice; public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true) { System.out.println("Today's choices are: "); System.out.println("\t1. Pizza 3$ "); System.out.println("\t2. Veg Burger 5$"); System.out.println("\t3. Biryani 70$ "); System.out.println("\t4. Chicken Soup 25$ "); System.out.println("--------------"); System.out.print("Enter your choice: "); int choice = sc.nextInt(); switch(choice) { case 1: calculatePrice(3); break; case 2: calculatePrice(5); break; case 3: calculatePrice(70); break; case 4: calculatePrice(25); break; default: System.out.println("INVALID CHOICE"); System.out.println("Total price: "+totalPrice+"$"); System.out.println("THANK YOU! AND HAVE A NICE DAY "); System.exit(0); } } // END of while } // END of main( ) method public static void calculatePrice(double Price) { totalPrice = totalPrice + Price; System.out.println("ordered successfully and current total is: "+totalPrice); } } // END
--------------------------------------------------------------------------------------------------------------------------
OUTPUT:
If the user chooses INVALID option in the first iteration itself, then
Hey, If you expected anything else please comment below the answer, I will modify it accordingly. THANK YOU!! If you like please UPVOTE.