diff --git a/src/main/java/christmas/ChristmasController.java b/src/main/java/christmas/ChristmasController.java index c60f1e61..adf9c26b 100644 --- a/src/main/java/christmas/ChristmasController.java +++ b/src/main/java/christmas/ChristmasController.java @@ -1,7 +1,11 @@ package christmas; +import christmas.view.InputView; + public class ChristmasController { - public void run(){ + InputView inputView = new InputView(); + public void run(){ + int reservationDate = inputView.readDate(); } } diff --git a/src/main/java/christmas/exception/InputException.java b/src/main/java/christmas/exception/InputException.java new file mode 100644 index 00000000..28c6da07 --- /dev/null +++ b/src/main/java/christmas/exception/InputException.java @@ -0,0 +1,7 @@ +package christmas.exception; + +public class InputException { + public void dateInputError() { + System.out.println("[ERROR] 유효하지 않은 날짜입니다. 다시 입력해 주세요."); + } +} diff --git a/src/main/java/christmas/view/InputView.java b/src/main/java/christmas/view/InputView.java new file mode 100644 index 00000000..d1db174a --- /dev/null +++ b/src/main/java/christmas/view/InputView.java @@ -0,0 +1,29 @@ +package christmas.view; + +import camp.nextstep.edu.missionutils.Console; +import christmas.exception.InputException; + +public class InputView { + InputException inputException = new InputException(); + + public int readDate() { + System.out.println("12월 중 식당 예상 방문 날짜는 언제인가요? (숫자만 입력해 주세요!)"); + int date = 0; + while(true){ + try{ + date = Integer.parseInt(Console.readLine()); + validateDate(date); + break; + } catch(IllegalArgumentException e){ + inputException.dateInputError(); + } + } + return date; + } + + private void validateDate(int date) throws IllegalArgumentException{ + if(date < 1 || date > 31){ + throw new IllegalArgumentException(); + } + } +}