Open chongweil907 opened 3 years ago
You can always call from the super class Event
's getters or toString()
.
@georgepwhuang There is only one attribute for my Event class which is the private final Function<Shop, Pair<Shop, Event>> func;
I thought that was for the subclasses of Event
though? I submitted with multiple methods onto CodeCrunch and passed fine
@georgepwhuang yea how do i do it for subclass of Event? I wrote the function in my super constructor and was wondering how can i get the toString method(). Thanks
Um I stored the necessary parameters I needed for the string in the toString() method as attributes of the Event
class, and some as the attributes of the subclass, so I didn't have to call from the lambda function.
So essentially I still kept the attributes in the Event
class from Project 1, but I added the function as an extra attribute.
@georgepwhuang By adding the function as an extra attribute, does your event class have a function attribute too? Because I thought the question states that your event class must have a method called execute, which is this.func.apply(shop). If you do have the func attribute, is it private final or public? Thank you in advance!
Yeah my function attribute is private final and I just assign a lambda function to the function attribute through the constructors of the subclasses using super()
.
So your super takes in (customer, shop, lambda)?
how can i get the information of the server that is allocated to that customer since it is wrapped inside a lambda
I save the server ID in Project 1 also lol
Your lambda in ArriveEvent should return either a Serve Event, Wait Event or a Leave Event. In the lambda function, you could use the find
function from Shop to find an available server and then map it to the respective Event, while passing in the server ID to the new event. orElseGet will help here too.
I see. I guess my question is where to define the lambda function when instantiating each event. For example, if the lambda is inside super(), then doesn't that mean ArriveEvent needs to provide the lambda for ServeEvent, and ServeEvent needs to provide the lambda for DoneEvent? Sorry a bit confused haha
I had the toString method just to pass level 2. I used sop
for the execute()
part
All of Arrive, Serve, Wait, Leave and Done extend Event. ArriveEvent and each of the other events are not related so you can just declare in the lambdas in each Event class's super(). E.g. Serve event's lambda will always return a Done event.
^ My ServeEvent can potentially return a ServeEvent lol, it depends on your implementation
Hi all, Does anyone has any idea on how to get the string representation of the event? Since everything is wrapped in a lambda, I am stuck on how to get the String representation out. I am assuming that we are not system.out.println it.
Thanks is advance !