Java Reference
In-Depth Information
Code 14.2
continued
The
Taxi
class as
an actor
public
class
Taxi
extends
Vehicle
{
private
Passenger passenger;
/**
* Constructor for objects of class Taxi
* @param company The taxi company. Must not be null.
* @param location The vehicle's starting point.
* Must not be null.
* @throws NullPointerException If company or location is null.
*/
public
Taxi(TaxiCompany company, Location location)
{
super
(company, location);
}
/**
* Carry out a taxi's actions.
*/
public
void
act()
{
Location target = getTargetLocation();
if
(target !=
null
){
// Find where to move to next.
Location next = getLocation().nextLocation(target);
setLocation(next);
if
(next.equals(target)) {
if
(passenger !=
null
){
notifyPassengerArrival(passenger);
offloadPassenger();
}
else
{
notifyPickupArrival();
}
}
}
else
{
incrementIdleCount();
}
}
/**
* Is the taxi free?
* @return Whether or not this taxi is free.
*/
Search WWH ::
Custom Search