-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathGameInputValidator.java
More file actions
41 lines (33 loc) · 1.13 KB
/
GameInputValidator.java
File metadata and controls
41 lines (33 loc) · 1.13 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 game;
public class GameInputValidator {
public boolean validateGameInput(String input){
//input 문자열의 길이 & 0이 포함되어 있는지 검사
if(input.length() != 3 || input.contains("0")){
System.out.println(Message.INVALID_INPUT_WARNING.getMsgStr());
return false;
}
return isNumber(input);
};
//input 문자열이 숫자로만 이루어져 있는지 검사
private boolean isNumber(String input){
try{
Integer.parseInt(input);
}catch (NumberFormatException numberFormatException){
System.out.println(Message.INVALID_INPUT_WARNING.getMsgStr());
return false;
}
return true;
}
public boolean validateRestartInput(String input) {
if(!isNumber(input)){
System.out.println(Message.INVALID_INPUT_WARNING.getMsgStr());
return false;
}
int n = Integer.parseInt(input);
if(n != 1 && n != 2){
System.out.println(Message.INVALID_INPUT_WARNING.getMsgStr());
return false;
}
return true;
}
}