Repository navigation
Expand file tree
/
Copy pathOrder.java
More file actions
123 lines (101 loc) · 3.44 KB
/
Copy pathOrder.java
File metadata and controls
123 lines (101 loc) · 3.44 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package model;
import controller.WoodTyper;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
/**
* @author Trevor Helms
*/
public class Order {
private Customer customer;
private String date;
private HashMap<String, String> orderItems;
public Order() {
customer = null;
date = "";
orderItems = new HashMap<>();
}
public Order(Customer customer, String date, HashMap<String, String> orderItems) {
this.customer = customer;
this.date = date;
this.orderItems = orderItems;
}
public Double getETA() {
Double eta = 0.0;
Double curr = 0.0;
Iterator it = orderItems.entrySet().iterator();
while (it.hasNext()) {
HashMap.Entry pair = (HashMap.Entry) it.next();
try {
WoodItem item = WoodTyper.getWoodTypeInstanceOf(pair.getKey().toString());
curr = item.getRealizedDeliveryTime(Integer.parseInt(pair.getValue().toString()));
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
// Get the max delivery time
if (curr > eta) {
eta = curr;
}
}
return eta;
}
public String getTotalPriceFormatted() {
Double total = 0.0;
Iterator it = orderItems.entrySet().iterator();
while (it.hasNext()) {
HashMap.Entry pair = (HashMap.Entry) it.next();
WoodItem item = null;
try {
item = WoodTyper.getWoodTypeInstanceOf(pair.getKey().toString());
total += item.getPrice();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String moneyString = formatter.format(total);
return moneyString;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public HashMap<String, String> getOrderItems() {
return orderItems;
}
public void addOrderItem(String woodType, String qty) {
this.orderItems.put(woodType, qty);
}
@Override
public String toString() {
String theString = "";
theString += "Order for: " + customer.getName() + "\n";
theString += "Delivery Address: " + customer.getAddress() + "\n";
theString += "Date Placed: " + date + "\n\n";
theString += "List of Wood Ordered (price/BF):" + "\n";
Iterator it = orderItems.entrySet().iterator();
while (it.hasNext()) {
HashMap.Entry pair = (HashMap.Entry) it.next();
theString += " - " + pair.getKey() + ": " + pair.getValue() + " @ ";
try {
theString += WoodTyper.getWoodTypeInstanceOf(pair.getKey().toString()).getPriceFormatted() + "\n";
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
theString += "\nEstimated Delivery Time: " + getETA() + " hours\n";
theString += "Total Price: " + getTotalPriceFormatted() + "\n";
return theString;
}
}