-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.java
More file actions
51 lines (40 loc) · 1.73 KB
/
Order.java
File metadata and controls
51 lines (40 loc) · 1.73 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
import java.util.ArrayList;
public class Order {
// Counter to generate unique order IDs
private static int orderCounter = 1;
// Order attributes
private int orderId;
private String customerName;
private ArrayList<Product> products;
private float total;
private String status;
private static boolean historyAdded = false; // Flag to check if order history has been added
private static ArrayList<Order> orders = new ArrayList<>(); // List to store all orders
// Constructor to create a new order
public Order(String customerName, ArrayList<Product> products, float total, String status) {
this.orderId = orderCounter++;
this.customerName = customerName;
this.products = products;
this.total = total;
this.status = status;
}
// Displays the order details in an invoice format
public void showOrder() {
System.out.println("\n========================");
System.out.println("Order ID : " + orderId);
System.out.println("Customer : " + customerName);
System.out.println("------------------------");
// Loop through products and display their names and quantities
for (Product product : products) {
System.out.println(product.getName() + " : " + product.getQuantity());
}
System.out.println("------------------------");
System.out.println("Total : Rs." + total);
System.out.println("Status : " + status);
System.out.println("========================");
}
// Returns the list of all orders
public static ArrayList<Order> getOrders() {
return orders;
}
}