first commit
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* Capture outline details of a vehicle.
|
||||
*
|
||||
* @author David J. Barnes and Michael Kölling
|
||||
* @version 2016.02.29
|
||||
*/
|
||||
public abstract class Vehicle
|
||||
{
|
||||
private TaxiCompany company;
|
||||
// Where the vehicle is.
|
||||
private Location location;
|
||||
// Where the vehicle is headed.
|
||||
private Location targetLocation;
|
||||
|
||||
/**
|
||||
* Constructor of class Vehicle
|
||||
* @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 Vehicle(TaxiCompany company, Location location)
|
||||
{
|
||||
if(company == null) {
|
||||
throw new NullPointerException("company");
|
||||
}
|
||||
if(location == null) {
|
||||
throw new NullPointerException("location");
|
||||
}
|
||||
this.company = company;
|
||||
this.location = location;
|
||||
targetLocation = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the company of our arrival at a pickup location.
|
||||
*/
|
||||
public void notifyPickupArrival()
|
||||
{
|
||||
company.arrivedAtPickup(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the company of our arrival at a
|
||||
* passenger's destination.
|
||||
* @param passenger The passenger who has arrived.
|
||||
*/
|
||||
public void notifyPassengerArrival(Passenger passenger)
|
||||
{
|
||||
company.arrivedAtDestination(this, passenger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive a pickup location.
|
||||
* How this is handled depends on the type of vehicle.
|
||||
* @param location The pickup location.
|
||||
*/
|
||||
public abstract void setPickupLocation(Location location);
|
||||
|
||||
/**
|
||||
* Receive a passenger.
|
||||
* How this is handled depends on the type of vehicle.
|
||||
* @param passenger The passenger being picked up.
|
||||
*/
|
||||
public abstract void pickup(Passenger passenger);
|
||||
|
||||
/**
|
||||
* Is the vehicle free?
|
||||
* @return Whether or not this vehicle is free.
|
||||
*/
|
||||
public abstract boolean isFree();
|
||||
|
||||
/**
|
||||
* Offload any passengers whose destination is the
|
||||
* current location.
|
||||
*/
|
||||
public abstract void offloadPassenger();
|
||||
|
||||
/**
|
||||
* Get the location.
|
||||
* @return Where this vehicle is currently located.
|
||||
*/
|
||||
public Location getLocation()
|
||||
{
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current location.
|
||||
* @param location Where it is. Must not be null.
|
||||
* @throws NullPointerException If location is null.
|
||||
*/
|
||||
public void setLocation(Location location)
|
||||
{
|
||||
if(location != null) {
|
||||
this.location = location;
|
||||
}
|
||||
else {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target location.
|
||||
* @return Where this vehicle is currently headed, or null
|
||||
* if it is idle.
|
||||
*/
|
||||
public Location getTargetLocation()
|
||||
{
|
||||
return targetLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the required target location.
|
||||
* @param location Where to go. Must not be null.
|
||||
* @throws NullPointerException If location is null.
|
||||
*/
|
||||
public void setTargetLocation(Location location)
|
||||
{
|
||||
if(location != null) {
|
||||
targetLocation = location;
|
||||
}
|
||||
else {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the target location.
|
||||
*/
|
||||
public void clearTargetLocation()
|
||||
{
|
||||
targetLocation = null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user