SHARE
TWEET

Untitled

a guest Mar 19th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package controller;
  2.  
  3. public class ThreadCarro extends Thread {
  4.    
  5.     private int id;
  6.     private static int posChegada;
  7.     private static int posSaida;
  8.    
  9.     public ThreadCarro(int id) {
  10.         this.id = id;
  11.     }
  12.    
  13.     @Override
  14.     public void run() {
  15.         // TODO Auto-generated method stub
  16.         super.run();
  17.     }
  18.    
  19.     private void carroAndando(){
  20.         int distFinal =
  21.                 (int)((Math.random() * 1001) + 1000);
  22.         int distPerc = 0;
  23.         int desloc =
  24.                 (int)((Math.random() * 41) + 60);
  25.         int tempo = 50;
  26.         while (distPerc < distFinal){
  27.             distPerc += desloc;
  28. //          distPerc = distPerc + desloc;
  29.             try {
  30.                 Thread.sleep(tempo);
  31.             } catch (InterruptedException e) {
  32.                 e.printStackTrace();
  33.             }
  34.             System.out.println("Carro #"+id+" andou "
  35.                     +distPerc+"m.");
  36.         }
  37.         posChegada++;
  38.         System.out.println("Carro #"+id+" foi o "
  39.                     +posChegada+" a chegar");
  40.     }
  41.  
  42.     private void carroParado(){
  43.        
  44.     }
  45.    
  46.     private void carroSaindo(){
  47.        
  48.     }
  49.    
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top