-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.java
More file actions
81 lines (62 loc) · 1.99 KB
/
Order.java
File metadata and controls
81 lines (62 loc) · 1.99 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
package onlinestore;
import java.time.LocalDate;
public class Order implements Cloneable {
private ProductList products;
private double totalPrice;
private LocalDate date;
//Constructor
public Order() {
this.products = new ProductList();
this.totalPrice = 0;
this.date = LocalDate.now();
}
//Copy Constructor
public Order(Order other) {
this.products = new ProductList(other.products);
this.totalPrice = other.totalPrice;
this.date = other.date;
}
public int getAmountProducts() {
return products.getAmountProducts();
}
public Product[] getProducts() {
return products.getProducts();
}
public double getTotalPrice() {
return totalPrice;
}
public LocalDate getDate() {
return date;
}
public void addProduct(Product product) {
products.addProduct(product);
totalPrice += product.getPrice();
if (product instanceof PackagedProduct) {
totalPrice += ((PackagedProduct) product).getPackagedPrice();
}
}
@Override
public boolean equals(Object other) {
if (!(other instanceof Order)) {
return false;
}
Order Order = (Order) other;
return this.products.equals(Order.products) && this.totalPrice == Order.totalPrice && this.date.equals(Order.date);
}
@Override
public Order clone() throws CloneNotSupportedException {
Order temp = (Order) super.clone();
temp.products = products.clone();
return temp;
}
@Override
public String toString() {
StringBuffer res = new StringBuffer(
"\nOrder summary:\n" + "\nDate Order: " + date + "\n" + "Amount of Products: "
+ products.getAmountProducts() + "\n" + "The items in the Order:\n"
);
res.append(products.toString());
res.append("Total Price Order: " + totalPrice + "$");
return res.toString();
}
}