forked from woowacourse-precourse/java-christmas-6
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. ChristmasController - orderList 필드를 통해 주문을 전달받음 2. InputView createReservationDateWhichIsNotBetweenOneAndThirtyOne() - readOrder() 적절한 양식의 주문이 보내질 떄까지 주문을 받아 OrderList 객체로 반환 3. InputException - orderInputError() 잘못된 양식의 주문이 보내질 때 에러 메시지를 반환 4. Menu - Enum 클래스 - 음식의 종류, 가격, 한국 음식 명을 저장 - isFoodOnMenu() 입력한 메뉴가 Menu 클래스에 있는지 판단한 후 boolean으로 결과값을 반환 5. OrderList - 음식당 주문 정보를 담은 Order 객체를 List에 담은 객체 - 사용자로부터 메뉴를 입력받으면 Order 객체를 생성한 후 List<Order>에 담아 반환 - findDuplicatedOrderInOrderList() orderList 객체에 order 객체를 추가할 때 중복 검사 후 중복됐다면 IllegalArgumentException 생성 6. Order - 개별 음식의 주문 정보를 가지고 있는 객체 - validateInput() Order 객체 생성시 전달된 매개변수가 알맞은 형식을 갖는지 확인 후 아니라면 IllegalArgumentException 생성 - validateQuantity() 주문 수량이 최소 수량 이상인지 확인 후 아니라면 IllegalArgumentException 생성 - validateFood() 주문 음식이 Menu에 존재하는지 확인 후 아니라면 IllegalArgumentException 생성 - isOrderSameAsOrderInList order 객체와 orderInList 객체의 음식이 동일한지 판별 후 boolean값 반환 - getFood() Order 객체 내부의 메소드에서 음식명을 확인할 때 사용하는 private 메소드
- Loading branch information
1 parent
92d18e0
commit 62a745d
Showing
6 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package christmas.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class OrderList { | ||
private final List<Order> orders; | ||
|
||
public OrderList(String[] inputOrders){ | ||
List<Order> 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<Order> orders) throws IllegalArgumentException { | ||
for(Order orderInList : orders){ | ||
if(orderInList.isOrderSameAsOrderInList(order)){ | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters