Java programming problem: Your restaurant business has been getting a lot of att
ID: 3871367 • Letter: J
Question
Java programming problem: Your restaurant business has been getting a lot of attention lately and the customers requested you to start an online delivery system. Write an application that presents the customer with a menu of the restaurant, let them choose the dishes from the menu, and show them the total price of the order. Procedure 1. Present the user with the menu containing various dishes and their prices 2. Ask the user to enter the number of different dishes they like to order 3. For each dish, ask how many servings of that dish they would like to order 4. Calculate the tax 5. Ask if they want to leave a tip and calculate the tip if they say yes 6. Show the user the breakdown of the prices and the total price for their order.
1 Sample Output:
Mr.K’s Indian Food Menu Item Price (in dollars)
1 Chicken Curry 10.69
2 Shrimp Curry 14.25
3 Naan 3.59
4 Chai 2.45
5 Sindhi Biryani 7.24
6 Lamb Biryani 15.59
7 Veg Biryani 11.27
8 Gobi Manchurian 10.35
9 Chana Masala 9.45
10 Kheer 4.99
How many different dishes would you like to order today? 3
Enter dish 1 [1-10] 1
How many servings of dish 1 would you like to order? 1
Enter dish 2 [1-10] 10
How many servings of dish 10 would you like to order? 2
Enter dish 3 [1-10] 5
How many servings of dish 5 would you like to order? 1
Enter the tax %: 5.5
Do you want to add tip? [’y’ - yes or ’n’ - no] y
Enter tip % [0-100]: 10
Price: 27.91
Tax (5.5%): 1.54
Tip (10.0%): 2.95
Total Amount: $32.4
Your order has been placed and will be delivered soon!
Explanation / Answer
import java.util.*;
public class Restaurant {
static String[] dish = new String[10];
static double[] price = new double[10];
ArrayList order = new ArrayList();
public static void main(String args[]) {
double total=0;
double totalprice=0;
double tax=0;
double tip=0;
init();
System.out.println("Mr.K’s Indian Food Menu Item Price (in dollars)");
System.out.println("1 Chicken Curry 10.69");
System.out.println("2 Shrimp Curry 14.25");
System.out.println("3 Naan 3.59");
System.out.println("4 Chai 2.45");
System.out.println("5 Sindhi Biryani 7.24");
System.out.println("6 Lamb Biryani 15.59");
System.out.println("7 Veg Biryani 11.27");
System.out.println("8 Gobi Manchurian 10.35");
System.out.println("9 Chana Masala 9.45");
System.out.println("10 Kheer 4.99");
System.out.println("How many different dishes would you like to order today?");
Scanner in = new Scanner(System.in);
int num = in.nextInt();
for(int i=0;i<num;i++){
System.out.println("Enter dish " + i + " [1-10]");
in = new Scanner(System.in);
int d=in.nextInt();
System.out.println("How many servings of dish " + i + " would you like to order?");
in = new Scanner(System.in);
int m=in.nextInt();
System.out.println(price[d-1]);
System.out.println(m);
total=total + price[d-1]*m;
totalprice=total;
}
System.out.println("Enter the tax %:");
in = new Scanner(System.in);
double taxpercent=in.nextDouble()/100;
tax = taxpercent* totalprice;
System.out.println("Do you want to add tip? [’y’ - yes or ’n’ - no]");
in = new Scanner(System.in);
String s = in.nextLine();
double tippercent=0;
if(s.equals("y")){
System.out.println("Enter tip % [0-100]:");
in = new Scanner(System.in);
tippercent=in.nextDouble()/100;
tip=tippercent*(totalprice+tax);
}
System.out.println("Price: " + totalprice);
System.out.println("Tax (" + taxpercent + "%): " + tax);
System.out.println("Tip (" + tippercent + "%): " + tip);
System.out.println("------------------------------------");
System.out.println("Total Amount: " + (total+tax+tip));
System.out.println("Your order has been placed and will be delivered soon! ");
}
public static void init(){
dish[0]="Chicken Curry";
dish[1]="Shrimp Curry";
dish[2]="Naan";
dish[3]="Chai";
dish[4]="Sindhi Biryani";
dish[5]="Lamb Biryani";
dish[6]="Veg Biryani";
dish[7]="Gobi Manchurian";
dish[8]="Chana Masala";
dish[9]="Kheer";
price[0]=10.69;
price[1]=14.25;
price[2]=3.59;
price[3]=2.45;
price[4]=7.24;
price[5]=15.59;
price[6]=11.27;
price[7]=10.35;
price[8]=9.45;
price[9]=4.99;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.