-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Restaurant.java
92 lines (75 loc) · 2.45 KB
/
Restaurant.java
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
86
87
88
89
90
91
92
package restaurantmanagementsystem;
import restaurantmanagementsystem.payment.Payment;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
public class Restaurant {
private static Restaurant instance;
private final List<MenuItem> menu;
private final Map<Integer, Order> orders;
private final List<Reservation> reservations;
private final Map<Integer, Payment> payments;
private final List<Staff> staff;
private Restaurant() {
menu = new CopyOnWriteArrayList<>();
orders = new ConcurrentHashMap<>();
reservations = new CopyOnWriteArrayList<>();
payments = new ConcurrentHashMap<>();
staff = new CopyOnWriteArrayList<>();
}
public static synchronized Restaurant getInstance() {
if (instance == null) {
instance = new Restaurant();
}
return instance;
}
public void addMenuItem(MenuItem item) {
menu.add(item);
}
public void removeMenuItem(MenuItem item) {
menu.remove(item);
}
public List<MenuItem> getMenu() {
return new ArrayList<>(menu);
}
public void placeOrder(Order order) {
orders.put(order.getId(), order);
// Notify kitchen staff to prepare the order
notifyKitchen(order);
}
public void updateOrderStatus(int orderId, OrderStatus status) {
Order order = orders.get(orderId);
if (order != null) {
order.setStatus(status);
// Notify relevant staff about the order status update
notifyStaff(order);
}
}
public void makeReservation(Reservation reservation) {
reservations.add(reservation);
}
public void cancelReservation(Reservation reservation) {
reservations.remove(reservation);
}
public void processPayment(Payment payment) {
payments.put(payment.getId(), payment);
// Process the payment through a payment gateway
// ...
}
public void addStaff(Staff staff) {
this.staff.add(staff);
}
public void removeStaff(Staff staff) {
this.staff.remove(staff);
}
private void notifyKitchen(Order order) {
// Notify kitchen staff to prepare the order
// ...
}
private void notifyStaff(Order order) {
// Notify relevant staff about the order status update
// ...
}
}