Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. package pl.pg;
  2.  
  3.  
  4. public class Kula {
  5.  
  6. public int wartosc;
  7. public boolean obciazenie;
  8.  
  9. public Kula (int liczba,boolean obciaz)
  10.  
  11. {
  12. obciazenie=obciaz;
  13. wartosc = liczba;
  14. }
  15. }
  16.  
  17.  
  18. /////////////////////////////////////////
  19.  
  20. package pl.pg;
  21.  
  22. import java.util.Random;
  23. import java.util.Timer;
  24. import java.util.TimerTask;
  25.  
  26.  
  27.  
  28.  
  29. public class MaszynaLosujaca
  30. {
  31.  
  32. Kula [] test;
  33. boolean sprawdz;
  34. int licznik=0;
  35. public int k;
  36. Kula pomocnicza;
  37. Random generator = new Random();
  38. Timer timer;
  39. public MaszynaLosujaca ()
  40.  
  41. {
  42.  
  43.  
  44. test = new Kula [49];
  45. for (int i=0; i<test.length; i++)
  46. { sprawdz = generator.nextBoolean();
  47. if (sprawdz == true)
  48. { licznik=licznik+1;}
  49. if (licznik>6)
  50. {sprawdz=false;}
  51. test[i] = new Kula (generator.nextInt(10000),sprawdz);
  52. }
  53. }
  54.  
  55. public void start(int ile)
  56. { k=ile*1000;
  57. timer = new Timer();
  58. timer.schedule(new MyTimerTask(),0,10);
  59.  
  60. }
  61.  
  62. public void stop()
  63. {
  64. timer.cancel();
  65. for (int i=0; i<6; i++)
  66. { System.out.println(test[i].wartosc );
  67. }
  68. }
  69. private void losuj()
  70. {
  71. int pierwszy=generator.nextInt(49);
  72. int drugi =generator.nextInt(49);
  73.  
  74.  
  75. if (pierwszy==drugi)
  76. {
  77. drugi=drugi+1;
  78. }
  79. swap(pierwszy,drugi);
  80.  
  81. for (int i=0; i<48;i++)
  82. {
  83. if (test[i].obciazenie==true)
  84. {
  85. if (i==0 && test[i].obciazenie==true)
  86. i=i;
  87. else
  88. swap(i-1,i);
  89. }
  90.  
  91. }
  92.  
  93.  
  94.  
  95. }
  96.  
  97. private void swap (int jeden , int dwa)
  98.  
  99. {
  100. pomocnicza=new Kula (test[jeden].wartosc,test[jeden].obciazenie);
  101. test[jeden].wartosc=test[dwa].wartosc;
  102. test[jeden].obciazenie=test[dwa].obciazenie;
  103. test[dwa].wartosc=pomocnicza.wartosc;
  104. test[dwa].obciazenie=pomocnicza.obciazenie;
  105.  
  106. }
  107.  
  108.  
  109. class MyTimerTask extends TimerTask
  110. {
  111. int z=0;
  112. @Override
  113. public void run()
  114. {
  115.  
  116. losuj();
  117. if (k==z)
  118. {
  119. stop();
  120. }
  121. z=z+10;
  122. }
  123. }
  124.  
  125.  
  126. ////////////////////////////////////////////////////
  127.  
  128.  
  129.  
  130. package pl.pg;
  131. import java.util.Scanner;
  132.  
  133.  
  134. public class PrezenterLotto {
  135. MaszynaLosujaca jeden;
  136.  
  137. PrezenterLotto()
  138. {
  139. jeden=new MaszynaLosujaca();
  140. System.out.println("Witamy w Lotto !");
  141. System.out.println("Prosze podac czas losowania w sekundach :");
  142. }
  143.  
  144. public static void main(String[] args)
  145. {
  146. Scanner in = new Scanner(System.in);
  147. PrezenterLotto test = new PrezenterLotto();
  148. int a = in.nextInt();
  149. test.jeden.start(a);
  150.  
  151. }
  152.  
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement