forked from next-step/java-baseball-playground
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAnswer.java
More file actions
27 lines (22 loc) · 726 Bytes
/
Answer.java
File metadata and controls
27 lines (22 loc) · 726 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
package util;
import java.util.ArrayList;
import static util.Constant.ANSWER_MAX_SIZE;
import static util.Constant.ANSWER_NUMBER_RANGE;
/**
* 정답 넘버 중복없는 3자리 생성하는 클래스
*/
public class Answer{
private final ArrayList<Integer> answerNum= new ArrayList<>();
public ArrayList<Integer> generateNumber() {
while (answerNum.size() < ANSWER_MAX_SIZE) {
int element = (int) (Math.random() * ANSWER_NUMBER_RANGE);
if(isNotContainsNumber(element)){
answerNum.add(element);
}
}
return this.answerNum;
}
private boolean isNotContainsNumber(int element) {
return !answerNum.contains(element);
}
}