-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathUser.java
More file actions
61 lines (44 loc) · 1.24 KB
/
User.java
File metadata and controls
61 lines (44 loc) · 1.24 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
53
54
55
56
57
58
59
60
61
package domain;
import java.util.ArrayList;
public class User {
private final ArrayList<Integer> numbers;
public ArrayList<Integer> getNumbers() {
return numbers;
}
public User() {
this.numbers = new ArrayList<>();
}
public void reset(){
this.numbers.clear();
}
public void userNumAdd(int num){
if(!this.numbers.contains(num))
{
this.numbers.add(num);
}
}
public void userNumConvert(String userInput){
for (int i = 0; i < userInput.length() ; i++) {
this.userNumAdd(userInput.charAt(i) - '0');
}
if (this.getNumbers().size() != 3) {
this.reset();
throw new IllegalArgumentException("잘못된 입력입니다.");
}
}
public void setNumbers(String num){
if (num.length() != 3 || !isNumeric(num)){
this.reset();
throw new IllegalArgumentException("잘못된 입력입니다.");
}
this.userNumConvert(num);
}
public static boolean isNumeric(String s) {
try {
Integer.parseInt(s);
} catch (NumberFormatException e) {
return false;
}
return !s.contains("0");
}
}