-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderSummary.java
More file actions
59 lines (47 loc) · 2.18 KB
/
OrderSummary.java
File metadata and controls
59 lines (47 loc) · 2.18 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
package BusinessLayer;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import BusinessLayer.OrderClasses.*;
import BusinessLayer.CustomerClasses.Customer;
import DataLayer.DataControl;
import BusinessLayer.OrderClasses.Order;
import BusinessLayer.ProductClasses.Product;
import UserInterfaceLayer.OrderSummaryUI;
public class OrderSummary {
@SuppressWarnings("unused")
public OrderSummary(Order userOrder, Customer currentCustomer) throws IOException {
System.out.println("[debug] : ****** Entering OrderSummary Class ******");
// Write the new order to ordersList.txt
int orderId = userOrder.getOrderId();
int customerId = currentCustomer.getCustomerId();
String customerName = currentCustomer.getFirstName() + " " + currentCustomer.getSurname();
String orderProductIds = userOrder.getOrderProductIdsToString();
DataControl.writeNewOrderToFile(orderId, customerId, customerName, orderProductIds);
// Reduce the stock amount of the products the customer is buying
DataControl.reduceProductOrderStock(userOrder.getOrderProductIds());
int[] orderProductIDs = userOrder.getOrderProductIds();
ArrayList<Product> myProducts = new ArrayList<Product>();
ArrayList<Product> allProducts = DataControl.getAllProductsFromFile();
for(int i = 0; i < orderProductIDs.length;i++){
for(int j = 0;j < allProducts.size(); j++){
if(orderProductIDs[i] == allProducts.get(j).getProductId()){
myProducts.add(allProducts.get(j));
}
}
}
ProductList listOfProducts = new ProductList();
for(int i =0; i < myProducts.size();i++){
myProducts.get(i).registerObserver(listOfProducts);
myProducts.get(i).setStock(myProducts.get(i).getStock() - 1);
myProducts.get(i).notifyObservers();
}
// Use Decorator Design pattern for printing receipt
Receipt headerReceipt = new HeaderReceipt(new BasicReceipt());
String postOrderDetails = headerReceipt.printReceipt();
postOrderDetails += userOrder.getPostOrderDetails();
Receipt shippingReceipt = new ShippingReceipt(new BasicReceipt());
postOrderDetails += shippingReceipt.printReceipt();
OrderSummaryUI createNewOrderSummaryUI = new OrderSummaryUI(postOrderDetails);
}
}