-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDiscountCalculator.java
More file actions
77 lines (63 loc) · 2.57 KB
/
Copy pathDiscountCalculator.java
File metadata and controls
77 lines (63 loc) · 2.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package christmas.service;
import christmas.model.domain.Order;
import java.time.DayOfWeek;
import java.time.LocalDate;
public class DiscountCalculator {
private static final int DAILY_DISCOUNT_START = 1000;
private static final int DAILY_DISCOUNT_INCREMENT = 100;
private static final int CATEGORY_DISCOUNT_AMOUNT = 2023;
private static final int SPECIAL_DAY_DISCOUNT = 1000;
private static final int GIFT_ELIGIBILITY_THRESHOLD = 120000;
private static final String MAIN_CATEGORY = "메인";
private static final String DESSERT_CATEGORY = "디저트";
private static final int CHRISTMAS_DAY = 25;
public int calculateDailyDiscount(int day) {
if (isInvalidDiscountDay(day)) {
return 0;
}
return DAILY_DISCOUNT_START + ((day - 1) * DAILY_DISCOUNT_INCREMENT);
}
public int calculateWeekdayDiscount(Order order, LocalDate visitDate) {
if (isWeekday(visitDate.getDayOfWeek())) {
return calculateCategoryDiscount(order, DESSERT_CATEGORY);
}
return 0;
}
public int calculateWeekendDiscount(Order order, LocalDate visitDate) {
if (isWeekend(visitDate.getDayOfWeek())) {
return calculateCategoryDiscount(order, MAIN_CATEGORY);
}
return 0;
}
public int calculateSpecialDayDiscount(LocalDate visitDate) {
if (isSpecialDay(visitDate)) {
return SPECIAL_DAY_DISCOUNT;
}
return 0;
}
public boolean isEligibleForGift(int totalPrice) {
return totalPrice >= GIFT_ELIGIBILITY_THRESHOLD;
}
private boolean isInvalidDiscountDay(int day) {
return day < 1 || day > 25;
}
private int calculateCategoryDiscount(Order order, String category) {
return order.getOrderDetails().entrySet().stream()
.filter(entry -> entry.getKey().getCategory().equals(category))
.mapToInt(entry -> CATEGORY_DISCOUNT_AMOUNT * entry.getValue())
.sum();
}
private boolean isWeekday(DayOfWeek dayOfWeek) {
return dayOfWeek == DayOfWeek.MONDAY ||
dayOfWeek == DayOfWeek.TUESDAY ||
dayOfWeek == DayOfWeek.WEDNESDAY ||
dayOfWeek == DayOfWeek.THURSDAY ||
dayOfWeek == DayOfWeek.SUNDAY;
}
private boolean isWeekend(DayOfWeek dayOfWeek) {
return dayOfWeek == DayOfWeek.FRIDAY || dayOfWeek == DayOfWeek.SATURDAY;
}
private boolean isSpecialDay(LocalDate date) {
return date.getDayOfWeek() == DayOfWeek.SUNDAY || date.getDayOfMonth() == CHRISTMAS_DAY;
}
}