forked from next-step/java-lotto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputView.java
More file actions
38 lines (29 loc) · 1.02 KB
/
InputView.java
File metadata and controls
38 lines (29 loc) · 1.02 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
37
38
package step2.view;
import java.util.Scanner;
public class InputView {
private static Scanner scanner = new Scanner(System.in);
public static int readAmountOfPurchase() {
return readInt("구매 금액을 입력해 주세요");
}
public static int readBonusNumber() {
return readInt("보너스 볼을 입력해 주세요.");
}
private static int readInt(String message) {
System.out.println(message);
return toInt(scanner.nextLine());
}
private static int toInt(String nextLine) {
try {
return Integer.parseInt(nextLine);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(nextLine + " : 유효한 정수 값이 아닙니다.");
}
}
public static String readWinningNumbers() {
return readString("지난 주 당첨 번호를 입력해 주세요");
}
private static String readString(String message) {
System.out.println(message);
return scanner.nextLine();
}
}