-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathLotteryNumbersClass.java
39 lines (34 loc) · 1.02 KB
/
LotteryNumbersClass.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
import java.util.ArrayList;
import java.util.Random;
public class LotteryNumbers {
private ArrayList<Integer> numbers;
private Random random = new Random();
public LotteryNumbers() {
// We'll format a list for the numbers
this.numbers = new ArrayList<Integer>();
// Draw numbers as LotteryNumbers is created
this.drawNumbers();
}
public ArrayList<Integer> numbers() {
return this.numbers;
}
public void drawNumbers() {
// Write the number drawing here using the method containsNumber()
int i = 0;
while (i < 7){
int randomNumber = random.nextInt(39) + 1;
if (!this.containsNumber(randomNumber)){
numbers.add(randomNumber);
i++;
}
}
}
public boolean containsNumber(int number) {
// Test here if the number is already in the drawn numbers
if (numbers.contains(number)){
return true;
}else{
return false;
}
}
}