forked from woowacourse/java-baseball-precourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpponent.java
More file actions
32 lines (26 loc) · 833 Bytes
/
Opponent.java
File metadata and controls
32 lines (26 loc) · 833 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
package baseball;
import camp.nextstep.edu.missionutils.Randoms;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
public class Opponent {
private List<Integer> number = new ArrayList<>();
public List<Integer> getNumber() {
if (number.isEmpty()) {
generateNumber();
}
return number;
}
private void generateNumber() {
HashSet<Integer> digitsWithoutZero = new HashSet<>();
while (digitsWithoutZero.size() < 3) {
digitsWithoutZero.add(getRandomDigitWithoutZero());
}
number.addAll(digitsWithoutZero);
}
private int getRandomDigitWithoutZero() {
final int startInclusive = 1;
final int endInclusive = 9;
return Randoms.pickNumberInRange(startInclusive, endInclusive);
}
}