-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLottery.java
41 lines (33 loc) · 1.12 KB
/
Lottery.java
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
import java.util.ArrayList;
import java.util.Random;
public class LotteryNumbers {
private ArrayList<Integer> numbers;
private Random random = new Random();
public LotteryNumbers() {
// Draw numbers as LotteryNumbers is created
this.drawNumbers();
}
public ArrayList<Integer> numbers() {
return this.numbers;
}
@SuppressWarnings("empty-statement")
public void drawNumbers() {
// We'll format a list for the numbers
this.numbers = new ArrayList<Integer>();
//Random random = new Random(39);
int newRandomDraw;
// Write the number drawing here using the method containsNumber()
while(this.numbers.size() < 7) {
newRandomDraw = this.random.nextInt(39) + 1;
if(this.containsNumber(newRandomDraw)) {
;
} else {
this.numbers.add(newRandomDraw);
}
}
}
public boolean containsNumber(int number) {
// Test here if the number is already in the drawn numbers
return this.numbers.contains(number);
}
}