-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW.java
68 lines (55 loc) · 1.58 KB
/
HW.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
import java.util.List;
import java.util.logging.Logger;
public class HW {
public boolean validateOrder(Order order) {
if (order.isSizeEmpty()) {
return false;
}
if (order.getTotalPrice()) {
return order.hasCustomerInfo();
}
return true;
}
class Order {
private final List<Item> items;
private final String customer;
Logger logger = Logger.getLogger("Order");
private Order(List<Item> items, String customer) {
this.items = items;
this.customer = customer;
}
boolean isSizeEmpty() {
if(items.isEmpty()) {
logger.info("주문 항목이 없습니다.");
return true;
}
return false;
}
public boolean hasCustomerInfo() {
if (customer == null || customer.isEmpty()) {
logger.info("사용자 정보가 없습니다.");
return false;
}
return true;
}
public boolean getTotalPrice() {
int totalPrice = items.stream()
.mapToInt(Item::getPrice)
.sum();
if (totalPrice > 0) {
return true;
}
logger.info("올바르지 않은 총 가격입니다.");
return false;
}
}
public class Item {
private final int price;
private Item(int price) {
this.price = price;
}
public int getPrice() {
return price;
}
}
}