public class NotifierCoach extends java.lang.Object implements Trailable
NotifierCoach
represents the next after the last Coach
of the train, which can be pulled and knows the Locomotive
that is pulling it
and the Controller
it was created by. It notifies its Controller
when the train it belongs to has no passengers.Constructor and Description |
---|
NotifierCoach(Controller controller,
Locomotive locomotive)
Creates a
NotifierCoach and sets its controller and locomotive to the
given Controller and Locomotive . |
Modifier and Type | Method and Description |
---|---|
void |
step(Slot nextSlot,
boolean hasPassengersAhead)
Implements the
step method of the Trailable interface. |
public NotifierCoach(Controller controller, Locomotive locomotive)
NotifierCoach
and sets its controller
and locomotive
to the
given Controller
and Locomotive
.controller
- the Controller
this NotifierCoach
is being created by,
which must be notified in case of an empty trainlocomotive
- the Locomotive
the last Coach
of which is to be pulling
this NotifierCoach
public void step(Slot nextSlot, boolean hasPassengersAhead)
step
method of the Trailable
interface. Since this
NotifierCoach
does not occupy a Slot
it does not move, rather it notifies
its Controller
when the train it belongs to has no passengers. This is determined by the
boolean parameter hasPassengersAhead
passed along the entire train. Being false at this stage
means there are no passengers ahead, and since this NotifierCoach
can not have any passengers,
there are no passengers on the train.