-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestaurantOrderingSystem.java
More file actions
85 lines (78 loc) · 2.74 KB
/
Copy pathRestaurantOrderingSystem.java
File metadata and controls
85 lines (78 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.util.ArrayList;
import java.util.Scanner;
class MenuItem {
String name;
double price;
MenuItem(String name, double price) {
this.name = name;
this.price = price;
}
}
class Order {
ArrayList<MenuItem> items = new ArrayList<>();
void addItem(MenuItem item) {
items.add(item);
}
void displayOrder() {
double total = 0;
System.out.println("Order:");
for (MenuItem item : items) {
System.out.println(item.name + " - $" + item.price);
total += item.price;
}
System.out.println("Total: $" + total);
}
}
public class RestaurantOrderingSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<MenuItem> menu = new ArrayList<>();
Order order = new Order();
menu.add(new MenuItem("Burger", 8.99));
menu.add(new MenuItem("Fries", 3.49));
menu.add(new MenuItem("Soda", 1.99));
menu.add(new MenuItem("Salad", 4.99));
while (true) {
System.out.println("\nRestaurant Ordering System:");
System.out.println("1. View Menu");
System.out.println("2. Place Order");
System.out.println("3. Display Bill");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.println("Menu:");
for (MenuItem item : menu) {
System.out.println(item.name + " - $" + item.price);
}
break;
case 2:
System.out.println("Enter the name of the item to order:");
scanner.nextLine();
String itemName = scanner.nextLine();
boolean found = false;
for (MenuItem item : menu) {
if (item.name.equalsIgnoreCase(itemName)) {
order.addItem(item);
System.out.println(item.name + " added to order.");
found = true;
break;
}
}
if (!found) {
System.out.println("Item not found in menu.");
}
break;
case 3:
order.displayOrder();
break;
case 4:
System.out.println("Exiting...");
return;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
}