-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCustomer.java
More file actions
59 lines (49 loc) · 1.57 KB
/
Customer.java
File metadata and controls
59 lines (49 loc) · 1.57 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 onlineshop;
import onlineshop.enums.Gender;
import onlineshop.order.Order;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class Customer {
/** Generates a new customer number for each customer */
private static Integer customerCounter = 1;
/** Converts the date string into a {@link Date} */
private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.mm.yyyy");
protected int customerNo;
protected String firstname;
protected String surname;
protected Gender gender;
protected LocalDate birthDate;
protected Cart cart;
protected List<Order> orders = new ArrayList<>();
public Customer() {
this.customerNo = customerCounter++;
}
public Customer(String firstname, String surname, Gender gender, String birthDate, Cart cart) {
this();
this.firstname = firstname;
this.surname = surname;
this.gender = gender;
this.birthDate = LocalDate.parse(birthDate, formatter);
this.cart = cart;
}
public void addOrder(Order order) {
orders.add(order);
// TODO: create a CSV for the order
}
public List<Order> getOrders() {
return orders;
}
public Order getOrderByOrderNumber(Integer orderNo) {
for(Order order : orders) {
if(order.getOrderNo() == orderNo) {
return order;
}
}
return null;
}
}