Java Reference
In-Depth Information
Code 14.2
continued
The Taxi class as
an actor
public boolean isFree()
{
return getTargetLocation() == null && passenger == null ;
}
/**
* Receive a pickup location. This becomes the
* target location.
* @location The pickup location.
*/
public void setPickupLocation(Location location)
{
setTargetLocation(location);
}
/**
* Receive a passenger.
* Set their destination as the target location.
* @param passenger The passenger.
*/
public void pickup(Passenger passenger)
{
this .passenger = passenger;
setTargetLocation(passenger.getDestination());
}
/**
* Offload the passenger.
*/
public void offloadPassenger()
{
passenger = null ;
clearTargetLocation();
}
/**
* Return details of the taxi, such as where it is.
* @return A string representation of the taxi.
*/
public String toString()
{
return "Taxi at " + getLocation();
}
}
Search WWH ::




Custom Search