-
Notifications
You must be signed in to change notification settings - Fork 589
Expand file tree
/
Copy pathComputer.java
More file actions
37 lines (26 loc) · 834 Bytes
/
Computer.java
File metadata and controls
37 lines (26 loc) · 834 Bytes
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
package baseball;
import camp.nextstep.edu.missionutils.Randoms;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
public class Computer {
private List<Integer> randomNumberList;
public Computer() {
this.randomNumberList = generateRandomNumberList();
}
private List<Integer> generateRandomNumberList() {
Set<Integer> notDuplicatedNumbers = new HashSet<>();
while (notDuplicatedNumbers.size() < 3) {
int num = Randoms.pickNumberInRange(1, 9); // 1 ~ 9 난수 생성
notDuplicatedNumbers.add(num);
}
return new ArrayList<>(notDuplicatedNumbers);
}
public List<Integer> getRandomNumberList() {
return this.randomNumberList;
}
public void resetRandomNumberList() {
this.randomNumberList = generateRandomNumberList();
}
}