-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathInputView.java
More file actions
35 lines (29 loc) · 1.12 KB
/
InputView.java
File metadata and controls
35 lines (29 loc) · 1.12 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
package view;
import java.util.Scanner;
import java.util.List;
import domain.Players;
public class InputView {
private static final Scanner scanner = new Scanner(System.in);
public static Players inputPlayers() {
System.out.println("참여할 사람 이름을 입력하세요. (이름은 쉼표(,)로 구분하세요)");
return new Players(parseCommaSeparatedString(scanner.nextLine()));
}
public static int inputLadderHeight() {
System.out.println("최대 사다리 높이는 몇 개 인가요?");
return parseInt(scanner.nextLine());
}
private static int parseInt(String input) {
try {
return Integer.parseInt(input);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("숫자를 입력해주세요.");
}
}
private static List<String> parseCommaSeparatedString(String input) {
try {
return List.of(input.split(","));
} catch (NullPointerException e) {
throw new IllegalArgumentException("쉼표(,)로 구분된 문자열을 입력해주세요.");
}
}
}