import java.util.Random;

class ServicePosition {

    private int minServiceTime;
    private int maxServiceTime;
    private Customer cust;
    private int serviceStartTime;
    private int serviceTime;
    private Random randy;
   
    public ServicePosition(int minServiceTime, int maxServiceTime) {
        this.minServiceTime = minServiceTime;
        this.maxServiceTime = maxServiceTime;
        randy = new Random();
    }
    
    public boolean isBusy() {
        return (cust != null);
    }
    
    public boolean isTransactionOver(int time) {
        return (time == getServiceEndTime());
    }
    
    public void startServing(Customer cust, int time) {
        this.cust = cust;
        this.serviceStartTime = time;
        this.serviceTime = getNewServiceTime();
    }

    public void finishServing() {
        cust = null;
    }
    
    public String toString() {
        String s = "Service position: ";
        if (isBusy()) {
            s = s + cust; 
        } else {
            s = s + "unoccupied";
        }
        return s;
    }
    
    private int getServiceEndTime() {
        return serviceStartTime + serviceTime;
    }
    
    private int getNewServiceTime() { 
        return minServiceTime + randy.nextInt(maxServiceTime);
    }
    
}
