-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.java
More file actions
28 lines (28 loc) · 1.42 KB
/
Copy pathOrder.java
File metadata and controls
28 lines (28 loc) · 1.42 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
package java_assign2;
import java.util.*;
class Order {
private int id;
private Customer customer;
private List<CartItem> items;
private double total;
private PaymentStatus paymentStatus;
private Delivery delivery;
public Order(int id, Customer customer, List<CartItem> cartItems, double total) {
this.id = id; this.customer = customer;
this.items = new ArrayList<>();
for (CartItem ci : cartItems) this.items.add(new CartItem(ci.getItem(), ci.getQuantity()));
this.total = total;
this.paymentStatus = PaymentStatus.PENDING;
this.delivery = new Delivery();
}
public boolean confirmPayment() { this.paymentStatus = PaymentStatus.SUCCESS; return true; }
public void dispatch() { delivery.updateStatus(DeliveryStatus.DISPATCHED); }
public PaymentStatus getPaymentStatus() { return paymentStatus; }
public Delivery getDelivery() { return delivery; }
public String getReceipt() {
StringBuilder sb = new StringBuilder("Order Receipt #" + id + "\nCustomer: " + customer.getName() + "\n\nItems:\n");
for (CartItem ci : items) sb.append(" ").append(ci.getItem().getName()).append(" x").append(ci.getQuantity()).append(" = ₹").append(ci.getTotal()).append("\n");
sb.append("\nOrder Total: ₹").append(total).append("\nPayment: ").append(paymentStatus).append("\n");
return sb.toString();
}
}