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 - int reservation 변수로 날짜 저장 2. InputView - readDate() 1 ~ 31 사이의 날짜를 입력할 때까지 입력 반복 - validateDate() 1 ~ 31 사이의 날짜를 입력하지 않으면 IllegalArgumentException 발생 3. InputException - dateInputError() 날짜 입력 잘못했을 때의 출력문구
- Loading branch information
1 parent
25fcec5
commit 0646029
Showing
3 changed files
with
41 additions
and
1 deletion.
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
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(); | ||
} | ||
} |
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,7 @@ | ||
package christmas.exception; | ||
|
||
public class InputException { | ||
public void dateInputError() { | ||
System.out.println("[ERROR] 유효하지 않은 날짜입니다. 다시 입력해 주세요."); | ||
} | ||
} |
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,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(); | ||
} | ||
} | ||
} |