public class PassengerCoach extends Coach
PassengerCoach
class implements the coaches carrying passengers of the trains in the game.
A PassengerCoach
is pulled by the Vehicle
it's connected to, that is, the
Vehicle
's nextCoach attribute is this.
This behaviour is provided by the Trailable
interface being implemented by Coach
,
and calling its step
method.
A PassengerCoach
also has a Color
and it can have passengers, who can get off,
and passengers at Station
s can get on it.Vehicle.Visitor
Constructor and Description |
---|
PassengerCoach(Slot currentPlace,
Color color,
boolean hasPassengers)
Creates a
PassengerCoach with a Color specified by color . |
Modifier and Type | Method and Description |
---|---|
void |
accept(Vehicle.Visitor visitor) |
void |
arrive(Station station)
Makes the passengers get off this
PassengerCoach at the Station
if the Station 's Colour matches this PassengerCoach 's. |
void |
depart(Station station)
Makes the waiting passengers at the
PassengerCoach get on this Vehicle
if the Station 's Colour matches this PassengerCoach 's. |
Color |
getColor() |
boolean |
hasPassengers() |
getCurrentPlace, getNextCoach, setCurrentPlace, setNextCoach, setNextCoach
public PassengerCoach(Slot currentPlace, Color color, boolean hasPassengers)
PassengerCoach
with a Color
specified by color
.
Its position is set to the position given by currentPlace
and the presence of its
passengers is set based on the parameter hasPassengers
.color
- color of the PassengerCoach
.
Available colors are specified by Color
.currentPlace
- a Slot
occupied by the PassengerCoach
hasPassengers
- indicator of the presence of passengers on the PassengerCoach
to be createdpublic void arrive(Station station)
PassengerCoach
at the Station
if the Station
's Colour
matches this PassengerCoach
's.public void depart(Station station)
PassengerCoach
get on this Vehicle
if the Station
's Colour
matches this PassengerCoach
's.public void accept(Vehicle.Visitor visitor)
public Color getColor()
public boolean hasPassengers()