-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderManagement.java
More file actions
67 lines (57 loc) · 1.85 KB
/
Copy pathOrderManagement.java
File metadata and controls
67 lines (57 loc) · 1.85 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
import java.util.*;
public class OrderManagement {
private Queue<Order> orderQueue;
private int orderIdCounter;
public OrderManagement() {
orderQueue = new LinkedList<>();
orderIdCounter = 1;
}
public void placeNewOrder(List<OrderItem> items) {
Order newOrder = new Order(orderIdCounter++, items);
orderQueue.add(newOrder);
System.out.println("Your Order placed successfully! Order ID: " + newOrder.orderId);
}
public void viewCurrentOrders() {
if (orderQueue.isEmpty()) {
System.out.println("No current orders.");
} else {
System.out.println("Current Orders:");
for (Order order : orderQueue) {
System.out.println("Order ID: " + order.orderId + " | Total Price: $" + order.totalPrice);
}
}
}
public void processNextOrder() {
if (orderQueue.isEmpty()) {
System.out.println("No orders to process.");
} else {
Order nextOrder = orderQueue.poll();
System.out.println("Processing Order ID: " + nextOrder.orderId + " | Total Price: $" + nextOrder.totalPrice);
}
}
}
class Order {
int orderId;
List<OrderItem> items;
double totalPrice;
Order(int orderId, List<OrderItem> items) {
this.orderId = orderId;
this.items = items;
this.totalPrice = calculateTotal();
}
private double calculateTotal() {
double total = 0;
for (OrderItem item : items) {
total += item.menuItem.price * item.quantity;
}
return total;
}
}
class OrderItem {
MenuItem menuItem;
int quantity;
OrderItem(MenuItem menuItem, int quantity) {
this.menuItem = menuItem;
this.quantity = quantity;
}
}