Skip to content

Commit

Permalink
feat: [#7] 주문할 메뉴와 개수 입력 기능
Browse files Browse the repository at this point in the history
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
MeanOfRedStone committed Nov 25, 2023
1 parent 92d18e0 commit 62a745d
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/christmas/ChristmasController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package christmas;

import christmas.domain.OrderList;
import christmas.domain.ReservationDate;
import christmas.view.InputView;

Expand All @@ -8,5 +9,6 @@ public class ChristmasController {

public void run(){
ReservationDate reservationDate = inputView.readDate();
OrderList orderList = inputView.readOrder();
}
}
35 changes: 35 additions & 0 deletions src/main/java/christmas/domain/Menu.java
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;
}

}
59 changes: 59 additions & 0 deletions src/main/java/christmas/domain/Order.java
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;
}
}
26 changes: 26 additions & 0 deletions src/main/java/christmas/domain/OrderList.java
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();
}
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/christmas/exception/InputException.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ public class InputException {
public void dateInputError() {
System.out.println("[ERROR] 유효하지 않은 날짜입니다. 다시 입력해 주세요.");
}

public void orderInputError() {
System.out.println( "[ERROR] 유효하지 않은 주문입니다. 다시 입력해 주세요.");
}
}
16 changes: 16 additions & 0 deletions src/main/java/christmas/view/InputView.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}
}

0 comments on commit 62a745d

Please sign in to comment.