Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package priprema;
- public class Priprema {
- public static volatile char [] rec= new char[12];
- public static final char[] abeceda = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
- public static final char[] popoka = {'P','O','P','O','K','A'};
- public static final char[] tepetl = {'T','E','P','E','T','L'};
- public static void main(String[] args) {
- for(int i = 0; i<12;i++){
- int t;
- double c;
- c=Math.random()*26;
- t=(int)c;
- rec[i]=abeceda[t];
- }
- System.out.println(rec);
- Menjac m1,m2;
- m1=new Menjac(100);
- m2=new Menjac(150);
- }
- }
- /////////////////////////////////////////////////
- package priprema;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class Menjac extends Thread {
- private int delay;
- public Menjac(int delay) {
- this.delay = delay;
- start();
- }
- private void spavaj(){
- try {
- Thread.sleep(this.delay);
- } catch (InterruptedException ex) {
- Logger.getLogger(Menjac.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- @Override
- public void run(){
- if(this.delay>110){
- for(int i = 0; i<6;i++){
- while (Priprema.rec[i]!=Priprema.popoka[i]) {
- menjaj(i);
- spavaj();
- }
- }
- }
- else{
- for(int i = 6; i<12;i++){
- while (Priprema.rec[i]!=Priprema.tepetl[i-6]) {
- menjaj(i);
- spavaj();
- }
- }
- }
- }
- private static synchronized void menjaj(int n){
- int t;
- double r = Math.random()*26;
- t=(int)r;
- Priprema.rec[n]=Priprema.abeceda[t];
- System.out.println(Priprema.rec);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment