/* An instance of this class represents a customer who arrives ** at a place of business (e.g., a bank), waits in a queue for ** service, receives that service, and then departs. ** The relevant facts about such a customer is their arrival time, ** the amount of time that servicing them takes, and the time at ** which service has been completed. ** ** Note: This class is essentially the same as that found in ** "Object-Oriented Data Structers using Java", by Dale, Joyce, and Weems, ** (4th edition, Pearson) */ public class Customer { // instance variables // ------------------ protected final int ID; protected final int arrivalTime; protected final int serviceDuration; protected int finishTime; // constructor // ----------- public Customer(int ID, int arriveTime, int servDur) { this.ID = ID; this.arrivalTime = arriveTime; this.serviceDuration = servDur; this.finishTime = -1; // dummy value indicating "unknown" } // observers // --------- public int ID() { return ID; } public int arrivalTime() { return arrivalTime; } public int serviceDuration() { return serviceDuration; } public int finishTime() { return finishTime; } /* Returns how many units of time this customer waited ** before service began to be provided. ** pre: recordFinishTime() has been called */ public int waitTime() { return finishTime - (serviceDuration + arrivalTime); } @Override public String toString() { String result = "ID:" + ID + "; Arrival:" + arrivalTime + "; Service:" + serviceDuration; if (finishTime != -1) { result = result + "; Finish:" + finishTime + "; Waiting:" + waitTime(); } return result + '\n'; } // mutator // ------- /* Sets this customer's finish time to the value indicated. */ public void recordFinishTime(int t) { finishTime = t; } }