nus/ArrivalEvent.java
Yadunand Prem 08f94aa5d3 init
2022-08-25 17:25:02 +08:00

34 lines
1.0 KiB
Java

class ArrivalEvent extends BaseShopEvent {
double serviceTime;
public ArrivalEvent(double time, int customerId, boolean[] available, double serviceTime) {
super(time, customerId, available);
this.availableCounters = available;
this.serviceTime = serviceTime;
}
@Override
public Event[] simulate() {
int counter = -1;
for (int i = 0; i < this.availableCounters.length; i++) {
if (this.availableCounters[i]) {
counter = i;
break;
}
}
if (counter == -1) {
return new Event[] { new DepartureEvent(this.getTime(), customerId, availableCounters) };
}
return new Event[] {
new ServiceBeginEvent(this.getTime(), this.customerId, this.availableCounters, this.serviceTime,
counter) };
}
@Override
public String toString() {
return super.toString() + String.format(": Customer %d arrives", this.customerId);
}
}