feat: add Lab4

This commit is contained in:
Yadunand Prem
2022-09-15 11:21:56 +08:00
parent c4d857ed02
commit 46d4fa5e9d
116 changed files with 912 additions and 2 deletions

View File

@@ -0,0 +1,34 @@
/**
* The ServiceBeginEvent is an Event which handles the starting of a service.
* It handles occupying a counter and also generating a serviceEndEvent
*
* @author Yadunand Prem
* @version CS2030S AY22/23 Semester 2
*/
class ServiceBeginEvent extends Event {
private ServiceCounter counter;
private Customer customer;
private Shop shop;
public ServiceBeginEvent(double time, Customer customer, Shop shop, ServiceCounter counter) {
super(time);
this.customer = customer;
this.shop = shop;
this.counter = counter;
}
@Override
public String toString() {
return super.toString()
+ String.format(": %s service begin (by %s)", this.customer, this.counter);
}
@Override
public Event[] simulate() {
this.counter.occupy();
double endTime = this.getTime() + this.customer.getServiceTime();
return new Event[] {
new ServiceEndEvent(endTime, this.customer, this.shop, this.counter) };
}
}