Skip to content

Commit

Permalink
feat: [#4] 식당 방문 날짜 입력 기능 추가
Browse files Browse the repository at this point in the history
1. ChristmasController
- int reservation 변수로 날짜 저장

2. InputView
- readDate()
1 ~ 31 사이의 날짜를 입력할 때까지 입력 반복
- validateDate()
1 ~ 31 사이의 날짜를 입력하지 않으면 IllegalArgumentException 발생

3. InputException
- dateInputError()
날짜 입력 잘못했을 때의 출력문구
  • Loading branch information
MeanOfRedStone committed Nov 22, 2023
1 parent 25fcec5 commit 0646029
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/christmas/ChristmasController.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
7 changes: 7 additions & 0 deletions src/main/java/christmas/exception/InputException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package christmas.exception;

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

0 comments on commit 0646029

Please sign in to comment.