-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathInputView.java
More file actions
52 lines (42 loc) · 1.47 KB
/
InputView.java
File metadata and controls
52 lines (42 loc) · 1.47 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
51
52
package view;
import domain.GameCounter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
public class InputView {
private static final BufferedReader BUFFERED_READER = new BufferedReader(new InputStreamReader(System.in));
private static final String DELIMITER = ",";
private InputView() {
}
public static GameCounter inputGameCount() {
OutputView.printGameCounterInput();
String inputNumber = nextLine();
validateGameCount(inputNumber);
return new GameCounter(inputNumber);
}
private static void validateGameCount(String input) {
if (input == null || input.isEmpty()) {
throw new IllegalArgumentException("[ERROR] 숫자를 입력해주세요.");
}
}
public static List<String> inputCarNames() {
OutputView.printCarInput();
String input = nextLine();
validateCarNames(input);
return Arrays.asList(input.split(DELIMITER));
}
private static void validateCarNames(String input) {
if (input == null || input.isEmpty()) {
throw new IllegalArgumentException("[ERROR] 이름을 입력해 주세요.");
}
}
private static String nextLine() {
try {
return BUFFERED_READER.readLine();
} catch (IOException e) {
throw new IllegalArgumentException("[ERROR] 잘못된 입력입니다.");
}
}
}