-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathAnswerEntity.java
More file actions
39 lines (33 loc) · 870 Bytes
/
AnswerEntity.java
File metadata and controls
39 lines (33 loc) · 870 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
38
39
package game;
import java.util.Random;
public class AnswerEntity {
private int[] answer;
private boolean[] check;
AnswerEntity(){
this.answer = new int[3];
}
public void init(){
Random random = new Random();
check = new boolean[10];
for(int idx = 0; idx < 3; idx++){
int num = random.nextInt(9) + 1;
if(checkDuplicationAndInsert(num, idx)) idx--;
}
}
private boolean checkDuplicationAndInsert(int num, int idx){
if(!check[num]){
answer[idx] = num;
check[num] = true;
return false;
}
return true;
}
public int[] getAnswer(){
return this.answer;
}
public void setAnswer(int n1, int n2, int n3){
this.answer[0] = n1;
this.answer[1] = n2;
this.answer[2] = n3;
}
}