-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathInputView.java
More file actions
50 lines (41 loc) · 1.52 KB
/
InputView.java
File metadata and controls
50 lines (41 loc) · 1.52 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
39
40
41
42
43
44
45
46
47
48
49
50
package lotto.view;
import org.kokodak.Console;
import java.util.ArrayList;
import java.util.List;
public class InputView {
public static int inputMyMoney() {
System.out.println("구입금액을 입력해 주세요.");
try {
return Integer.parseInt(Console.readLine());
} catch (NumberFormatException e) {
ExceptionMessage.isNotNumber();
throw new IllegalArgumentException();
}
}
public static List<Integer> inputWinningNumber() {
System.out.println("당첨 번호를 입력해 주세요.");
return numberList(Console.readLine());
}
private static List<Integer> numberList(String winningNumber) {
String[] numbers = winningNumber.split(",");
ArrayList<Integer> winningNumberList = new ArrayList<Integer>();
for (int i = 0; i < numbers.length; i++) {
try {
winningNumberList.add(Integer.parseInt(numbers[i]));
} catch (NumberFormatException e){
ExceptionMessage.isNotNumber();
throw new IllegalArgumentException();
}
}
return winningNumberList;
}
public static int inputBonusNumber(List<Integer> winningNumber) {
System.out.println("보너스 번호를 입력해 주세요.");
try {
return Integer.parseInt(Console.readLine());
} catch (NumberFormatException e) {
ExceptionMessage.isNotNumber();
throw new IllegalArgumentException();
}
}
}