Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.pg;
- public class Kula {
- public int wartosc;
- public boolean obciazenie;
- public Kula (int liczba,boolean obciaz)
- {
- obciazenie=obciaz;
- wartosc = liczba;
- }
- }
- /////////////////////////////////////////
- package pl.pg;
- import java.util.Random;
- import java.util.Timer;
- import java.util.TimerTask;
- public class MaszynaLosujaca
- {
- Kula [] test;
- boolean sprawdz;
- int licznik=0;
- public int k;
- Kula pomocnicza;
- Random generator = new Random();
- Timer timer;
- public MaszynaLosujaca ()
- {
- test = new Kula [49];
- for (int i=0; i<test.length; i++)
- { sprawdz = generator.nextBoolean();
- if (sprawdz == true)
- { licznik=licznik+1;}
- if (licznik>6)
- {sprawdz=false;}
- test[i] = new Kula (generator.nextInt(10000),sprawdz);
- }
- }
- public void start(int ile)
- { k=ile*1000;
- timer = new Timer();
- timer.schedule(new MyTimerTask(),0,10);
- }
- public void stop()
- {
- timer.cancel();
- for (int i=0; i<6; i++)
- { System.out.println(test[i].wartosc );
- }
- }
- private void losuj()
- {
- int pierwszy=generator.nextInt(49);
- int drugi =generator.nextInt(49);
- if (pierwszy==drugi)
- {
- drugi=drugi+1;
- }
- swap(pierwszy,drugi);
- for (int i=0; i<48;i++)
- {
- if (test[i].obciazenie==true)
- {
- if (i==0 && test[i].obciazenie==true)
- i=i;
- else
- swap(i-1,i);
- }
- }
- }
- private void swap (int jeden , int dwa)
- {
- pomocnicza=new Kula (test[jeden].wartosc,test[jeden].obciazenie);
- test[jeden].wartosc=test[dwa].wartosc;
- test[jeden].obciazenie=test[dwa].obciazenie;
- test[dwa].wartosc=pomocnicza.wartosc;
- test[dwa].obciazenie=pomocnicza.obciazenie;
- }
- class MyTimerTask extends TimerTask
- {
- int z=0;
- @Override
- public void run()
- {
- losuj();
- if (k==z)
- {
- stop();
- }
- z=z+10;
- }
- }
- ////////////////////////////////////////////////////
- package pl.pg;
- import java.util.Scanner;
- public class PrezenterLotto {
- MaszynaLosujaca jeden;
- PrezenterLotto()
- {
- jeden=new MaszynaLosujaca();
- System.out.println("Witamy w Lotto !");
- System.out.println("Prosze podac czas losowania w sekundach :");
- }
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- PrezenterLotto test = new PrezenterLotto();
- int a = in.nextInt();
- test.jeden.start(a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement