Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.Random;
- public class Lottery {
- private ArrayList<Integer> numbers;
- public Lottery() {
- this.drawNumbers();
- }
- public ArrayList<Integer> numbers() {
- return this.numbers;
- }
- public void drawNumbers() {
- Random random = new Random();
- this.numbers = new ArrayList<Integer>();
- int num;
- while(numbers.size() < 7) {
- num = random.nextInt(39)+1;
- if(!this.containsNumber(num)) {
- this.numbers.add(num);
- }
- }
- }
- public boolean containsNumber(int number) {
- return this.numbers.contains(number);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement