Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Random;
- public class LottoRivi {
- private ArrayList<Integer> numerot;
- private Random random;
- //private arvoNumerot;
- public LottoRivi() {
- // Alustetaan lista numeroille
- this.numerot = new ArrayList<Integer>();
- // Arvo numerot heti LottoRivin luomisen yhteydessä
- this.arvoNumerot();
- this.random = new Random();
- }
- public ArrayList<Integer> numerot() {
- return this.numerot;
- }
- public boolean sisaltaaNumeron(int numero) {
- // Testaa tässä onko numero jo arvottujen numeroiden joukossa
- if (numerot.contains(numero)) {
- return false;
- } else {
- return true;
- }
- }
- public void arvoNumerot() {
- // Kirjoita numeroiden arvonta tänne käyttämällä metodia sisaltaaNumeron()
- int i = 0;
- while (i < 7) {
- int apu = this.random.nextInt(39);
- int lottonumero = apu + 1;
- if (sisaltaaNumeron(lottonumero)) {
- numerot.add(lottonumero);
- i++;
- } else {
- continue;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement