Hakunin

OBP2_priprema1_popokatepetl

Nov 10th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1. package priprema;
  2.  
  3. public class Priprema {
  4.     public static volatile char [] rec= new char[12];
  5.     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'};
  6.     public static final char[] popoka = {'P','O','P','O','K','A'};
  7.     public static final char[] tepetl = {'T','E','P','E','T','L'};
  8.    
  9.     public static void main(String[] args) {
  10.         for(int i = 0; i<12;i++){
  11.             int t;
  12.             double c;
  13.             c=Math.random()*26;
  14.             t=(int)c;
  15.            
  16.             rec[i]=abeceda[t];
  17.         }
  18.         System.out.println(rec);
  19.        
  20.         Menjac m1,m2;
  21.         m1=new Menjac(100);
  22.         m2=new Menjac(150);
  23.     }
  24. }
  25.  
  26. /////////////////////////////////////////////////
  27.  
  28. package priprema;
  29.  
  30. import java.util.logging.Level;
  31. import java.util.logging.Logger;
  32.  
  33. public class Menjac extends Thread {
  34.     private int delay;
  35.  
  36.     public Menjac(int delay) {
  37.         this.delay = delay;
  38.         start();
  39.     }
  40.    
  41.     private void spavaj(){
  42.         try {
  43.             Thread.sleep(this.delay);
  44.         } catch (InterruptedException ex) {
  45.             Logger.getLogger(Menjac.class.getName()).log(Level.SEVERE, null, ex);
  46.         }
  47.     }
  48.    
  49.     @Override
  50.     public void run(){
  51.         if(this.delay>110){
  52.             for(int i = 0; i<6;i++){
  53.                 while (Priprema.rec[i]!=Priprema.popoka[i]) {
  54.                     menjaj(i);
  55.                     spavaj();
  56.                 }
  57.             }
  58.         }
  59.         else{
  60.             for(int i = 6; i<12;i++){
  61.                 while (Priprema.rec[i]!=Priprema.tepetl[i-6]) {
  62.                     menjaj(i);
  63.                     spavaj();
  64.                 }
  65.             }
  66.         }
  67.     }
  68.    
  69.     private static synchronized void menjaj(int n){
  70.         int t;
  71.         double r = Math.random()*26;
  72.         t=(int)r;
  73.         Priprema.rec[n]=Priprema.abeceda[t];
  74.         System.out.println(Priprema.rec);
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment