-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathInputMoney.java
More file actions
36 lines (30 loc) · 1.07 KB
/
InputMoney.java
File metadata and controls
36 lines (30 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package lotto.view;
import camp.nextstep.edu.missionutils.Console;
public class InputMoney {
// 로또 구입 금액 입력
public int getMoney() {
while(true) { // 예외 발생 시 반복적인 입력을 받기 위한 반복문
try {
System.out.println("Please enter a money.");
int money = Integer.parseInt(Console.readLine());
checkMoney(money);
return money;
}
// 숫자 이외의 입력
catch (NumberFormatException e) {
System.out.println("[ERROR] It is not a number.");
}
// 1000원으로 나누어 떨어지지 않는 입력
catch (IllegalArgumentException e) {
System.out.println("[ERROR] It is not a valid money.");
}
}
}
// 1000원으로 나누어 떨어지지 않는 입력 체크 함수
public void checkMoney(int money) {
int value = money % 1000;
if(value != 0) {
throw new IllegalArgumentException();
}
}
}