-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathInputView.java
More file actions
34 lines (27 loc) · 1.17 KB
/
InputView.java
File metadata and controls
34 lines (27 loc) · 1.17 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
package view;
import utils.IntegerParser;
import utils.StringParser;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
public class InputView {
private static final String READ_CAR_NAME_MESSAGE = "경주할 자동차 이름을 입력하세요(이름은 쉼표(,)를 기준으로 구분).";
private static final String READ_ATTEMPT_NUMBER_MESSAGE = "시도할 회수는 몇회인가요?";
private static final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
public static List<String> readCarNames() throws IOException {
System.out.println(READ_CAR_NAME_MESSAGE);
String input = bufferedReader.readLine();
return StringParser.splitByComma(input);
}
public static int readAttemptNumber() throws IOException {
try {
System.out.println(READ_ATTEMPT_NUMBER_MESSAGE);
String input = bufferedReader.readLine();
return IntegerParser.parse(input);
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
return readAttemptNumber();
}
}
}