Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab14;
- import java.util.Random;
- public class Client extends Thread {
- Balance b;
- Random r = new Random();
- public Client(String name, Balance b) {
- System.out.println("Created Client " + name);
- super();
- this.b = b;
- setName(name);
- }
- public void run() {
- while(b.bankceiling() > 0) {
- if(r.nextInt() %2 == 0)
- System.out.println(getName() + " deposited "
- + b.put(Math.abs(r.nextInt() %50))
- + " euros in the joint account!(" + b.bankceiling() + ")");
- else
- System.out.println(getName() + " extracted "
- + b.put(Math.abs(r.nextInt() %50))
- + " euros from the joint account!(" + b.bankceiling() + ")");
- try {
- Thread.sleep(r.nextInt(100));
- }
- catch (InterruptedException e) {
- System.out.println("eroare " + e.getMessage());
- }
- }
- }
- }
- class Account {
- public static void main(String argv[]) throws Exception {
- Balance b = new Balance(70);
- final int noclients = 3;
- Client c[] = new Client[noclients];
- for (int i=0; i < noclients; i++)
- c[i] = new Client("Client" + b, i);
- for (int i=0; i < noclients; i++) {
- System.out.println(c[i].getName() + " is at the bank!");
- c[i].start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement