-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrder.java
99 lines (75 loc) · 2.2 KB
/
Order.java
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
import java.sql.Date;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.ArrayList;
public class Order {
private int orderID;
private String customerName;
private double totalCost;
private double totalTax;
private String date;
private List<OrderLine> lines;
private static final DecimalFormat dfZero = new DecimalFormat("0.00");
public Order() {
lines = new ArrayList<>();
}
public String getDate() {
return date;
}
public void setDate(String dateIn) {
this.date = dateIn;
}
public double getTotalCost() {
return totalCost;
}
public void setTotalCost(double totalCost) {
this.totalCost = totalCost;
}
public double getTotalTax() {
return totalTax;
}
public void setTotalTax(double totalTax) {
this.totalTax = Double.parseDouble(dfZero.format(totalTax));
}
public int getOrderID() {
return orderID;
}
public void setOrderID(int orderID) {
this.orderID = orderID;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public void addLine(OrderLine line) {
lines.add(line);
}
public void removeLine(OrderLine line) {
lines.remove(line);
}
public List<OrderLine> getLines() {
return lines;
}
@Override
public String toString() {
String result = "orderID: " + this.orderID + "\tCustomer: " + this.customerName + "\tTotal: " + this.totalCost
+ "\tTax: " + this.totalTax + "\tDate: " + this.date + "\n";
for (OrderLine line: lines) {
result += line.toString() + "\n";
}
return result;
}
public String summary() {
String result = " OrderID: " + this.orderID
+ "\n Date: " + this.date
+ "\nCustomer: " + this.customerName
+ "\n Cost: " + this.totalCost
+ "\n Tax: " + this.totalTax;
return result;
}
}