diff --git a/src/main/java/christmas/ChristmasController.java b/src/main/java/christmas/ChristmasController.java index 028df94f..cfd206a1 100644 --- a/src/main/java/christmas/ChristmasController.java +++ b/src/main/java/christmas/ChristmasController.java @@ -1,5 +1,6 @@ package christmas; +import christmas.domain.OrderList; import christmas.domain.ReservationDate; import christmas.view.InputView; @@ -8,5 +9,6 @@ public class ChristmasController { public void run(){ ReservationDate reservationDate = inputView.readDate(); + OrderList orderList = inputView.readOrder(); } } diff --git a/src/main/java/christmas/domain/Menu.java b/src/main/java/christmas/domain/Menu.java new file mode 100644 index 00000000..6f128cfc --- /dev/null +++ b/src/main/java/christmas/domain/Menu.java @@ -0,0 +1,35 @@ +package christmas.domain; + +public enum Menu { + SOFT_MUSHROOM_SOUP("appetizer", 6_000, "양송이수프"), + TAPAS("appetizer", 5_500, "타파스"), + CAESAR_SALAD("appetizer", 8_000, "시저샐러드"), + T_BONE_STEAK("main", 55_000, "티본스테이크"), + BARBEQUE_RIP("main", 54_000, "바비큐립"), + SEAFOOD_PASTA("main", 35_000, "해산물파스타"), + CHRISTMAS_PASTA("main", 25_000, "크리스마스파스타"), + CHOCO_CAKE("dessert", 15_000, "초코케이크"), + ICE_CREAM("dessert", 5_000, "아이스크림"), + ZERO_COKE("drink", 3_000, "제로콜라"), + RED_WINE("drink", 60_000, "레드와인"), + CHAMPAGNE("drink", 25_000, "샴페인"); + + private final String menuType; + private final int price; + private final String koreanName; + + Menu(String menuType, int price, String koreanName){ + this.menuType = menuType; + this.price = price; + this.koreanName = koreanName; + } + + public boolean isFoodOnMenu(String food){ + if(food.equals(koreanName)){ + return true; + } + + return false; + } + +} diff --git a/src/main/java/christmas/domain/Order.java b/src/main/java/christmas/domain/Order.java new file mode 100644 index 00000000..fab9ba65 --- /dev/null +++ b/src/main/java/christmas/domain/Order.java @@ -0,0 +1,59 @@ +package christmas.domain; + +import java.util.Arrays; + +public class Order { + static final int FOOD_INDEX = 0; + static final int QUANTITY_INDEX = 1; + static final int MINIMUM_ORDER_QUANTITY = 1; + + private final String food; + private final int quantity; + + public Order(String inputOrder) throws IllegalArgumentException { + String[] foodAndQuantity = inputOrder.split("-"); + validateInput(foodAndQuantity); + + String food = foodAndQuantity[FOOD_INDEX]; + int quantity = Integer.parseInt(foodAndQuantity[QUANTITY_INDEX]); + validateQuantity(quantity); + validateFood(food); + + this.quantity = quantity; + this.food = food; + } + + private void validateInput(String[] foodAndQuantity) throws IllegalArgumentException { + if(foodAndQuantity.length != 2){ + throw new IllegalArgumentException(); + } + } + + private void validateQuantity(int quantity) throws IllegalArgumentException { + if(quantity < MINIMUM_ORDER_QUANTITY){ + throw new IllegalArgumentException(); + } + } + + private void validateFood(String food) throws IllegalArgumentException{ + boolean isInMenu = false; + for(Menu menu : Menu.values()){ + if(menu.isFoodOnMenu(food)){ + isInMenu = true; + } + } + if(!isInMenu){ + throw new IllegalArgumentException(); + } + } + + public boolean isOrderSameAsOrderInList(Order order){ + boolean isSame = food.equals(order.getFood()); + + return isSame; + } + + private String getFood(){ + return food; + } +} \ No newline at end of file diff --git a/src/main/java/christmas/domain/OrderList.java b/src/main/java/christmas/domain/OrderList.java new file mode 100644 index 00000000..9bbc65d5 --- /dev/null +++ b/src/main/java/christmas/domain/OrderList.java @@ -0,0 +1,26 @@ +package christmas.domain; + +import java.util.ArrayList; +import java.util.List; + +public class OrderList { + private final List orders; + + public OrderList(String[] inputOrders){ + List orders = new ArrayList<>(); + for(String inputOrder : inputOrders){ + Order order = new Order(inputOrder); + findDuplicatedOrderInOrderList(order, orders); + orders.add(order); + } + this.orders = orders; + } + + private void findDuplicatedOrderInOrderList(Order order, List orders) throws IllegalArgumentException { + for(Order orderInList : orders){ + if(orderInList.isOrderSameAsOrderInList(order)){ + throw new IllegalArgumentException(); + } + } + } +} diff --git a/src/main/java/christmas/exception/InputException.java b/src/main/java/christmas/exception/InputException.java index 28c6da07..ffa3fe72 100644 --- a/src/main/java/christmas/exception/InputException.java +++ b/src/main/java/christmas/exception/InputException.java @@ -4,4 +4,8 @@ public class InputException { public void dateInputError() { System.out.println("[ERROR] 유효하지 않은 날짜입니다. 다시 입력해 주세요."); } + + public void orderInputError() { + System.out.println( "[ERROR] 유효하지 않은 주문입니다. 다시 입력해 주세요."); + } } diff --git a/src/main/java/christmas/view/InputView.java b/src/main/java/christmas/view/InputView.java index f3de949d..9c33bb6c 100644 --- a/src/main/java/christmas/view/InputView.java +++ b/src/main/java/christmas/view/InputView.java @@ -1,6 +1,7 @@ package christmas.view; import camp.nextstep.edu.missionutils.Console; +import christmas.domain.OrderList; import christmas.domain.ReservationDate; import christmas.exception.InputException; @@ -21,4 +22,19 @@ public ReservationDate readDate() { } return date; } + + public OrderList readOrder() { + System.out.println("주문하실 메뉴를 메뉴와 개수를 알려 주세요. (e.g. 해산물파스타-2,레드와인-1,초코케이크-1)"); + OrderList orderList; + while(true){ + try{ + String[] inputOrders = Console.readLine().split(","); + orderList = new OrderList(inputOrders); + break; + } catch(IllegalArgumentException e){ + inputException.orderInputError(); + } + } + return orderList; + } }