Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1.  
  2. import java.util.ArrayList;
  3. import java.util.Random;
  4.  
  5. public class LottoRivi {
  6.  
  7. private ArrayList<Integer> numerot;
  8. private Random random;
  9. //private arvoNumerot;
  10.  
  11. public LottoRivi() {
  12. // Alustetaan lista numeroille
  13. this.numerot = new ArrayList<Integer>();
  14. // Arvo numerot heti LottoRivin luomisen yhteydessä
  15. this.arvoNumerot();
  16. this.random = new Random();
  17. }
  18.  
  19. public ArrayList<Integer> numerot() {
  20. return this.numerot;
  21. }
  22.  
  23. public boolean sisaltaaNumeron(int numero) {
  24. // Testaa tässä onko numero jo arvottujen numeroiden joukossa
  25. if (numerot.contains(numero)) {
  26. return false;
  27. } else {
  28. return true;
  29. }
  30. }
  31.  
  32. public void arvoNumerot() {
  33. // Kirjoita numeroiden arvonta tänne käyttämällä metodia sisaltaaNumeron()
  34. int i = 0;
  35. while (i < 7) {
  36. int apu = this.random.nextInt(39);
  37. int lottonumero = apu + 1;
  38.  
  39. if (sisaltaaNumeron(lottonumero)) {
  40. numerot.add(lottonumero);
  41. i++;
  42. } else {
  43. continue;
  44. }
  45.  
  46. }
  47. }
  48.  
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement