-
Notifications
You must be signed in to change notification settings - Fork 901
Expand file tree
/
Copy pathInputView.java
More file actions
41 lines (35 loc) · 1.06 KB
/
InputView.java
File metadata and controls
41 lines (35 loc) · 1.06 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
package baseboll.myTrial.second.view;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class InputView {
private final BufferedReader br;
public InputView() {
this.br = new BufferedReader(new InputStreamReader(System.in));
}
public String getInput() throws IOException {
System.out.println("숫자를 입력 해 주세요");
String input = br.readLine();
if (!isProperInput(input)) {
getInput();
}
return input;
}
public boolean wantContinue() throws IOException {
String input = br.readLine();
return input.equals("1");
}
public boolean isProperInput(String s) {
if (s.length() != 3) {
System.out.println("3자리 숫자를 입력해주세요");
return false;
}
try {
Integer.parseInt(s);
} catch (NumberFormatException e) {
System.out.println("숫자만 입력해주세요");
return false;
}
return true;
}
}