/** * This class represents a customer. * * @author Franck van Breugel */ public class Customer extends Thread { private int id; private WaitingRoom room; private Barber barber; /** * Initializes this customer with the given id, waiting room and barber. * * @param id the id of this customer. * @param room the waiting room of the barber of this customer. * @param barber the barber of this customer. */ public Customer(int id, WaitingRoom room, Barber barber) { this.id = id; this.room = room; this.barber = barber; } /** * A day of a customer. */ public void run() { final int MILLISECONDS_PER_SECOND = 1000; try { this.sleep((long) (Math.random() * MILLISECONDS_PER_SECOND)); } catch (InterruptedException e) {} // enters if (this.room.enter(id)) { // wakes up the barber if asleep this.barber.wake(); // waits this.room.wait(id); // leaves this.room.leave(id); } } }