daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Jan 16th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package lab14;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Client extends Thread {
  6.     Balance b;
  7.    
  8.     Random r = new Random();
  9.  
  10.     public Client(String name, Balance b) {
  11.         System.out.println("Created Client " + name);
  12.         super();
  13.         this.b = b;
  14.         setName(name);
  15.     }
  16.    
  17.     public void run() {
  18.         while(b.bankceiling() > 0) {
  19.             if(r.nextInt() %2 == 0)
  20.                 System.out.println(getName() + " deposited "
  21.                         + b.put(Math.abs(r.nextInt() %50))
  22.                         + " euros in the joint account!(" + b.bankceiling() + ")");
  23.            
  24.             else
  25.                 System.out.println(getName() + " extracted "
  26.                         + b.put(Math.abs(r.nextInt() %50))
  27.                         + " euros from the joint account!(" + b.bankceiling() + ")");
  28.            
  29.             try {
  30.                 Thread.sleep(r.nextInt(100));
  31.             }
  32.             catch (InterruptedException e) {
  33.                 System.out.println("eroare " + e.getMessage());
  34.             }      
  35.         }
  36.     }
  37. }
  38.  
  39.  
  40. class Account {
  41.     public static void main(String argv[]) throws Exception {
  42.         Balance b = new Balance(70);
  43.        
  44.         final int noclients = 3;
  45.        
  46.         Client c[] = new Client[noclients];
  47.         for (int i=0; i < noclients; i++)
  48.             c[i] = new Client("Client" + b, i);
  49.         for (int i=0; i < noclients; i++) {
  50.             System.out.println(c[i].getName() + " is at the bank!");
  51.             c[i].start();
  52.         }
  53.     }
  54. }
RAW Paste Data
Top