-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomers.java
More file actions
51 lines (44 loc) · 1.82 KB
/
Customers.java
File metadata and controls
51 lines (44 loc) · 1.82 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
package customer;
import arrays.DArray;
import group.Group;
import group.GroupType;
import group.Groups;
public class Customers extends DArray<Customer>{
private final Groups allGroups = Groups.getInstance();
private static Customers allCustomers;
public static Customers getInstance() {
if (allCustomers == null) {
allCustomers = new Customers();
}
return allCustomers;
}
private Customers() {}
// refresh 함수가 호출되는 경우
// 1. 분류기준 바뀔 때
// 2. 새로운 고객이 들어올 때
public void refresh() {
for(int i=0; i< allCustomers.size(); i++){
Customer customer = allCustomers.get(i);
Group group = findGroup(customer.getTotalTime(), customer.getTotalPay());
customer.setGroup(group);
}
}
/**
* 시간과 돈을 매개변수로 받아 해당하는 등급을 반환
* */
public Group findGroup(int totalTime, int totalPay){
try {
if(totalTime >= allGroups.find(GroupType.VVIP).getParameter().getMinTime() && totalPay>=allGroups.find(GroupType.VVIP).getParameter().getMinPay()){
return allGroups.find(GroupType.VVIP);
} else if (totalTime >= allGroups.find(GroupType.VIP).getParameter().getMinTime() && totalPay>=allGroups.find(GroupType.VIP).getParameter().getMinPay()) {
return allGroups.find(GroupType.VIP);
} else if (totalTime >= allGroups.find(GroupType.GENERAL).getParameter().getMinTime() && totalPay>=allGroups.find(GroupType.GENERAL).getParameter().getMinPay()) {
return allGroups.find(GroupType.GENERAL);
} else{
return allGroups.find(GroupType.NONE);
}
} catch (NullPointerException e){
return null;
}
}
}