first commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=Demo()
|
||||
comment0.text=\n\ Create\ some\ sample\ objects\ for\ the\ demo.\n
|
||||
comment1.params=
|
||||
comment1.target=void\ pickupTest()
|
||||
comment1.text=\n\ Request\ a\ pickup\ for\ a\ new\ passenger.\n\ The\ request\ will\ fail\ in\ this\ version.\n
|
||||
numComments=2
|
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Set up a passenger-source and taxi-company, to illustrate
|
||||
* the scenario of requesting a pickup.
|
||||
*
|
||||
* @author David J. Barnes and Michael Kölling
|
||||
* @version 2016.02.29
|
||||
*/
|
||||
public class Demo
|
||||
{
|
||||
private PassengerSource source;
|
||||
private TaxiCompany company;
|
||||
|
||||
/**
|
||||
* Create some sample objects for the demo.
|
||||
*/
|
||||
public Demo()
|
||||
{
|
||||
company = new TaxiCompany();
|
||||
source = new PassengerSource(company);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request a pickup for a new passenger.
|
||||
* The request will fail in this version.
|
||||
*/
|
||||
public void pickupTest()
|
||||
{
|
||||
if(source.requestPickup()) {
|
||||
System.out.println("Pickup request succeeded.");
|
||||
}
|
||||
else {
|
||||
System.out.println("Pickup request failed.");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=Location()
|
||||
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Location\n
|
||||
numComments=1
|
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Model a location in a city.
|
||||
*
|
||||
* @author David J. Barnes and Michael Kölling
|
||||
* @version 2016.02.29
|
||||
*/
|
||||
public class Location
|
||||
{
|
||||
/**
|
||||
* Constructor for objects of class Location
|
||||
*/
|
||||
public Location()
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
#BlueJ class context
|
||||
comment0.params=pickup\ destination
|
||||
comment0.target=Passenger(Location,\ Location)
|
||||
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Passenger\n\ @param\ pickup\ The\ pickup\ location,\ must\ not\ be\ null.\n\ @param\ destination\ The\ destination\ location,\ must\ not\ be\ null.\n\ @throws\ NullPointerException\ If\ either\ location\ is\ null.\n
|
||||
comment1.params=
|
||||
comment1.target=Location\ getPickupLocation()
|
||||
comment1.text=\n\ @return\ The\ pickup\ location.\n
|
||||
comment2.params=
|
||||
comment2.target=Location\ getDestination()
|
||||
comment2.text=\n\ @return\ The\ destination\ location.\n
|
||||
numComments=3
|
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Model a passenger wishing to get from one
|
||||
* location to another.
|
||||
*
|
||||
* @author David J. Barnes and Michael Kölling
|
||||
* @version 2016.02.29
|
||||
*/
|
||||
public class Passenger
|
||||
{
|
||||
private Location pickup;
|
||||
private Location destination;
|
||||
|
||||
/**
|
||||
* Constructor for objects of class Passenger
|
||||
* @param pickup The pickup location, must not be null.
|
||||
* @param destination The destination location, must not be null.
|
||||
* @throws NullPointerException If either location is null.
|
||||
*/
|
||||
public Passenger(Location pickup, Location destination)
|
||||
{
|
||||
if(pickup == null) {
|
||||
throw new NullPointerException("Pickup location");
|
||||
}
|
||||
if(destination == null) {
|
||||
throw new NullPointerException("Destination location");
|
||||
}
|
||||
this.pickup = pickup;
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The pickup location.
|
||||
*/
|
||||
public Location getPickupLocation()
|
||||
{
|
||||
return pickup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The destination location.
|
||||
*/
|
||||
public Location getDestination()
|
||||
{
|
||||
return destination;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
#BlueJ class context
|
||||
comment0.params=company
|
||||
comment0.target=PassengerSource(TaxiCompany)
|
||||
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ PassengerSource.\n\ @param\ company\ The\ company\ to\ be\ used.\ Must\ not\ be\ null.\n\ @throws\ NullPointerException\ if\ company\ is\ null.\n
|
||||
comment1.params=
|
||||
comment1.target=boolean\ requestPickup()
|
||||
comment1.text=\n\ Have\ the\ source\ generate\ a\ new\ passenger\ and\n\ request\ a\ pickup\ from\ the\ company.\n\ @return\ true\ If\ the\ request\ succeeds,\ false\ otherwise.\n
|
||||
comment2.params=
|
||||
comment2.target=Passenger\ createPassenger()
|
||||
comment2.text=\n\ Create\ a\ new\ passenger.\n\ @return\ The\ created\ passenger.\n
|
||||
numComments=3
|
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Simulate passengers requesting rides from a taxi company.
|
||||
* Passengers should be generated at random intervals.
|
||||
*
|
||||
* @author David J. Barnes and Michael Kölling
|
||||
* @version 2016.02.29
|
||||
*/
|
||||
public class PassengerSource
|
||||
{
|
||||
private TaxiCompany company;
|
||||
|
||||
/**
|
||||
* Constructor for objects of class PassengerSource.
|
||||
* @param company The company to be used. Must not be null.
|
||||
* @throws NullPointerException if company is null.
|
||||
*/
|
||||
public PassengerSource(TaxiCompany company)
|
||||
{
|
||||
if(company == null) {
|
||||
throw new NullPointerException("company");
|
||||
}
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
/**
|
||||
* Have the source generate a new passenger and
|
||||
* request a pickup from the company.
|
||||
* @return true If the request succeeds, false otherwise.
|
||||
*/
|
||||
public boolean requestPickup()
|
||||
{
|
||||
Passenger passenger = createPassenger();
|
||||
return company.requestPickup(passenger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new passenger.
|
||||
* @return The created passenger.
|
||||
*/
|
||||
private Passenger createPassenger()
|
||||
{
|
||||
return new Passenger(new Location(), new Location());
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
Project: taxi-company-outline
|
||||
Authors: David J. Barnes and Michael Kölling
|
||||
|
||||
This project is part of the material for chapter 14 of the book
|
||||
|
||||
Objects First with Java - A Practical Introduction using BlueJ
|
||||
Sixth edition
|
||||
David J. Barnes and Michael Kölling
|
||||
Pearson Education, 2016
|
||||
|
||||
This project provides a partial implementation of a simulation of
|
||||
taxis operating on a city grid to pick up and transport passengers.
|
||||
|
||||
This is the first stage of this project. It illustrates an outline
|
||||
implementation form derived from CRC interaction.
|
||||
|
||||
How to start this project:
|
||||
Create a TaxiCompany and a PassengerSource. Call the requestPickup
|
||||
method of the source. However, as there are no vehicles created,
|
||||
no passengers will ever be picked up. (This functionality is also
|
||||
capture in the Demo class.)
|
||||
|
||||
Create at least one Taxi in the constructor of TaxiCompany and
|
||||
add it to the vehicles collection. Then a passenger will have
|
||||
a taxi scheduled to pick them up. However, as vehicles do not
|
||||
yet move, they never will be picked up.
|
@@ -0,0 +1,20 @@
|
||||
#BlueJ class context
|
||||
comment0.params=company\ location
|
||||
comment0.target=Shuttle(TaxiCompany,\ Location)
|
||||
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Shuttle\n\ @param\ company\ The\ taxi\ company.\ Must\ not\ be\ null.\n\ @param\ location\ The\ vehicle's\ starting\ point.\ Must\ not\ be\ null.\n\ @throws\ NullPointerException\ If\ company\ or\ location\ is\ null.\n
|
||||
comment1.params=
|
||||
comment1.target=boolean\ isFree()
|
||||
comment1.text=\n\ Is\ the\ shuttle\ free?\n\ @return\ Whether\ or\ not\ this\ vehicle\ is\ free.\n
|
||||
comment2.params=location
|
||||
comment2.target=void\ setPickupLocation(Location)
|
||||
comment2.text=\n\ Receive\ a\ pickup\ location.\n\ @param\ location\ The\ pickup\ location.\n
|
||||
comment3.params=passenger
|
||||
comment3.target=void\ pickup(Passenger)
|
||||
comment3.text=\n\ Receive\ a\ passenger.\n\ Add\ their\ destination\ to\ the\ list.\n\ @param\ passenger\ The\ passenger\ being\ picked\ up.\n
|
||||
comment4.params=
|
||||
comment4.target=void\ chooseTargetLocation()
|
||||
comment4.text=\n\ Decide\ where\ to\ go\ next,\ based\ on\ the\ list\ of\n\ possible\ destinations.\n
|
||||
comment5.params=
|
||||
comment5.target=void\ offloadPassenger()
|
||||
comment5.text=\n\ Offload\ a\ passenger\ whose\ destination\ is\ the\n\ current\ location.\n
|
||||
numComments=6
|
@@ -0,0 +1,76 @@
|
||||
import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* A shuttle is able to carry multiple passengers.
|
||||
*
|
||||
* @author David J. Barnes and Michael Kölling
|
||||
* @version 2016.02.29
|
||||
*/
|
||||
public class Shuttle extends Vehicle
|
||||
{
|
||||
// The list of destinations for the shuttle.
|
||||
private List<Location> destinations;
|
||||
// The list of passengers on the shuttle.
|
||||
private List<Passenger> passengers;
|
||||
|
||||
/**
|
||||
* Constructor for objects of class Shuttle
|
||||
* @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 Shuttle(TaxiCompany company, Location location)
|
||||
{
|
||||
super(company, location);
|
||||
destinations = new LinkedList<>();
|
||||
passengers = new LinkedList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the shuttle free?
|
||||
* @return Whether or not this vehicle is free.
|
||||
*/
|
||||
public boolean isFree()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive a pickup location.
|
||||
* @param location The pickup location.
|
||||
*/
|
||||
public void setPickupLocation(Location location)
|
||||
{
|
||||
destinations.add(location);
|
||||
chooseTargetLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive a passenger.
|
||||
* Add their destination to the list.
|
||||
* @param passenger The passenger being picked up.
|
||||
*/
|
||||
public void pickup(Passenger passenger)
|
||||
{
|
||||
passengers.add(passenger);
|
||||
destinations.add(passenger.getDestination());
|
||||
chooseTargetLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Decide where to go next, based on the list of
|
||||
* possible destinations.
|
||||
*/
|
||||
private void chooseTargetLocation()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Offload a passenger whose destination is the
|
||||
* current location.
|
||||
*/
|
||||
public void offloadPassenger()
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
#BlueJ class context
|
||||
comment0.params=company\ location
|
||||
comment0.target=Taxi(TaxiCompany,\ Location)
|
||||
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Taxi\n\ @param\ company\ The\ taxi\ company.\ Must\ not\ be\ null.\n\ @param\ location\ The\ vehicle's\ starting\ point.\n\ Must\ not\ be\ null.\n\ @throws\ NullPointerException\ If\ company\ or\ location\ is\ null.\n
|
||||
comment1.params=
|
||||
comment1.target=boolean\ isFree()
|
||||
comment1.text=\n\ Is\ the\ taxi\ free?\n\ @return\ Whether\ or\ not\ this\ taxi\ is\ free.\n
|
||||
comment2.params=location
|
||||
comment2.target=void\ setPickupLocation(Location)
|
||||
comment2.text=\n\ Receive\ a\ pickup\ location.\ This\ becomes\ the\n\ target\ location.\n\ @param\ location\ The\ pickup\ location.\n
|
||||
comment3.params=passenger
|
||||
comment3.target=void\ pickup(Passenger)
|
||||
comment3.text=\n\ Receive\ a\ passenger.\n\ Set\ their\ destination\ as\ the\ target\ location.\n\ @param\ passenger\ The\ passenger.\n
|
||||
comment4.params=
|
||||
comment4.target=void\ offloadPassenger()
|
||||
comment4.text=\n\ Offload\ the\ passenger.\n
|
||||
numComments=5
|
@@ -0,0 +1,58 @@
|
||||
|
||||
/**
|
||||
* A taxi is able to carry a single passenger.
|
||||
*
|
||||
* @author David J. Barnes and Michael Kölling
|
||||
* @version 2016.02.29
|
||||
*/
|
||||
public class Taxi extends Vehicle
|
||||
{
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the taxi free?
|
||||
* @return Whether or not this taxi is free.
|
||||
*/
|
||||
public boolean isFree()
|
||||
{
|
||||
return getTargetLocation() == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive a pickup location. This becomes the
|
||||
* target location.
|
||||
* @param 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)
|
||||
{
|
||||
setTargetLocation(passenger.getDestination());
|
||||
}
|
||||
|
||||
/**
|
||||
* Offload the passenger.
|
||||
*/
|
||||
public void offloadPassenger()
|
||||
{
|
||||
clearTargetLocation();
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=TaxiCompany()
|
||||
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ TaxiCompany\n
|
||||
comment1.params=passenger
|
||||
comment1.target=boolean\ requestPickup(Passenger)
|
||||
comment1.text=\n\ Request\ a\ pickup\ for\ the\ given\ passenger.\n\ @param\ passenger\ The\ passenger\ requesting\ a\ pickup.\n\ @return\ Whether\ a\ free\ vehicle\ is\ available.\n
|
||||
comment2.params=vehicle
|
||||
comment2.target=void\ arrivedAtPickup(Vehicle)
|
||||
comment2.text=\n\ A\ vehicle\ has\ arrived\ at\ a\ pickup\ point.\n\ @param\ vehicle\ The\ vehicle\ at\ the\ pickup\ point.\n
|
||||
comment3.params=vehicle\ passenger
|
||||
comment3.target=void\ arrivedAtDestination(Vehicle,\ Passenger)
|
||||
comment3.text=\n\ A\ vehicle\ has\ arrived\ at\ a\ passenger's\ destination.\n\ @param\ vehicle\ The\ vehicle\ at\ the\ destination.\n\ @param\ passenger\ The\ passenger\ being\ dropped\ off.\n
|
||||
comment4.params=
|
||||
comment4.target=Vehicle\ scheduleVehicle()
|
||||
comment4.text=\n\ Find\ a\ free\ vehicle,\ if\ any.\n\ @return\ A\ free\ vehicle,\ or\ null\ if\ there\ is\ none.\n
|
||||
numComments=5
|
@@ -0,0 +1,74 @@
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* Model the operation of a taxi company, operating different
|
||||
* types of vehicle.
|
||||
*
|
||||
* @author David J. Barnes and Michael Kölling
|
||||
* @version 2016.02.29
|
||||
*/
|
||||
public class TaxiCompany
|
||||
{
|
||||
private List<Vehicle> vehicles;
|
||||
|
||||
/**
|
||||
* Constructor for objects of class TaxiCompany
|
||||
*/
|
||||
public TaxiCompany()
|
||||
{
|
||||
vehicles = new LinkedList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Request a pickup for the given passenger.
|
||||
* @param passenger The passenger requesting a pickup.
|
||||
* @return Whether a free vehicle is available.
|
||||
*/
|
||||
public boolean requestPickup(Passenger passenger)
|
||||
{
|
||||
Vehicle vehicle = scheduleVehicle();
|
||||
if(vehicle != null) {
|
||||
vehicle.setPickupLocation(passenger.getPickupLocation());
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A vehicle has arrived at a pickup point.
|
||||
* @param vehicle The vehicle at the pickup point.
|
||||
*/
|
||||
public void arrivedAtPickup(Vehicle vehicle)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* A vehicle has arrived at a passenger's destination.
|
||||
* @param vehicle The vehicle at the destination.
|
||||
* @param passenger The passenger being dropped off.
|
||||
*/
|
||||
public void arrivedAtDestination(Vehicle vehicle,
|
||||
Passenger passenger)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a free vehicle, if any.
|
||||
* @return A free vehicle, or null if there is none.
|
||||
*/
|
||||
private Vehicle scheduleVehicle()
|
||||
{
|
||||
Iterator<Vehicle> it = vehicles.iterator();
|
||||
while(it.hasNext()) {
|
||||
Vehicle vehicle = it.next();
|
||||
if(vehicle.isFree()) {
|
||||
return vehicle;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
#BlueJ class context
|
||||
comment0.params=company\ location
|
||||
comment0.target=Vehicle(TaxiCompany,\ Location)
|
||||
comment0.text=\n\ Constructor\ of\ class\ Vehicle\n\ @param\ company\ The\ taxi\ company.\ Must\ not\ be\ null.\n\ @param\ location\ The\ vehicle's\ starting\ point.\ Must\ not\ be\ null.\n\ @throws\ NullPointerException\ If\ company\ or\ location\ is\ null.\n
|
||||
comment1.params=
|
||||
comment1.target=void\ notifyPickupArrival()
|
||||
comment1.text=\n\ Notify\ the\ company\ of\ our\ arrival\ at\ a\ pickup\ location.\n
|
||||
comment10.params=location
|
||||
comment10.target=void\ setTargetLocation(Location)
|
||||
comment10.text=\n\ Set\ the\ required\ target\ location.\n\ @param\ location\ Where\ to\ go.\ Must\ not\ be\ null.\n\ @throws\ NullPointerException\ If\ location\ is\ null.\n
|
||||
comment11.params=
|
||||
comment11.target=void\ clearTargetLocation()
|
||||
comment11.text=\n\ Clear\ the\ target\ location.\n
|
||||
comment2.params=passenger
|
||||
comment2.target=void\ notifyPassengerArrival(Passenger)
|
||||
comment2.text=\n\ Notify\ the\ company\ of\ our\ arrival\ at\ a\n\ passenger's\ destination.\n\ @param\ passenger\ The\ passenger\ who\ has\ arrived.\n
|
||||
comment3.params=location
|
||||
comment3.target=void\ setPickupLocation(Location)
|
||||
comment3.text=\n\ Receive\ a\ pickup\ location.\n\ How\ this\ is\ handled\ depends\ on\ the\ type\ of\ vehicle.\n\ @param\ location\ The\ pickup\ location.\n
|
||||
comment4.params=passenger
|
||||
comment4.target=void\ pickup(Passenger)
|
||||
comment4.text=\n\ Receive\ a\ passenger.\n\ How\ this\ is\ handled\ depends\ on\ the\ type\ of\ vehicle.\n\ @param\ passenger\ The\ passenger\ being\ picked\ up.\n
|
||||
comment5.params=
|
||||
comment5.target=boolean\ isFree()
|
||||
comment5.text=\n\ Is\ the\ vehicle\ free?\n\ @return\ Whether\ or\ not\ this\ vehicle\ is\ free.\n
|
||||
comment6.params=
|
||||
comment6.target=void\ offloadPassenger()
|
||||
comment6.text=\n\ Offload\ any\ passengers\ whose\ destination\ is\ the\n\ current\ location.\n
|
||||
comment7.params=
|
||||
comment7.target=Location\ getLocation()
|
||||
comment7.text=\n\ Get\ the\ location.\n\ @return\ Where\ this\ vehicle\ is\ currently\ located.\n
|
||||
comment8.params=location
|
||||
comment8.target=void\ setLocation(Location)
|
||||
comment8.text=\n\ Set\ the\ current\ location.\n\ @param\ location\ Where\ it\ is.\ Must\ not\ be\ null.\n\ @throws\ NullPointerException\ If\ location\ is\ null.\n
|
||||
comment9.params=
|
||||
comment9.target=Location\ getTargetLocation()
|
||||
comment9.text=\n\ Get\ the\ target\ location.\n\ @return\ Where\ this\ vehicle\ is\ currently\ headed,\ or\ null\n\ \ \ \ \ \ \ \ \ if\ it\ is\ idle.\n
|
||||
numComments=12
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -0,0 +1,177 @@
|
||||
#BlueJ package file
|
||||
dependency1.from=Taxi
|
||||
dependency1.to=TaxiCompany
|
||||
dependency1.type=UsesDependency
|
||||
dependency10.from=TaxiCompany
|
||||
dependency10.to=Vehicle
|
||||
dependency10.type=UsesDependency
|
||||
dependency11.from=Passenger
|
||||
dependency11.to=Location
|
||||
dependency11.type=UsesDependency
|
||||
dependency12.from=PassengerSource
|
||||
dependency12.to=TaxiCompany
|
||||
dependency12.type=UsesDependency
|
||||
dependency13.from=PassengerSource
|
||||
dependency13.to=Passenger
|
||||
dependency13.type=UsesDependency
|
||||
dependency14.from=PassengerSource
|
||||
dependency14.to=Location
|
||||
dependency14.type=UsesDependency
|
||||
dependency15.from=Vehicle
|
||||
dependency15.to=TaxiCompany
|
||||
dependency15.type=UsesDependency
|
||||
dependency16.from=Vehicle
|
||||
dependency16.to=Location
|
||||
dependency16.type=UsesDependency
|
||||
dependency17.from=Vehicle
|
||||
dependency17.to=Passenger
|
||||
dependency17.type=UsesDependency
|
||||
dependency18.from=TaxiCompany
|
||||
dependency18.to=Taxi
|
||||
dependency18.type=UsesDependency
|
||||
dependency19.from=TaxiCompany
|
||||
dependency19.to=Location
|
||||
dependency19.type=UsesDependency
|
||||
dependency2.from=Taxi
|
||||
dependency2.to=Location
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=Taxi
|
||||
dependency3.to=Passenger
|
||||
dependency3.type=UsesDependency
|
||||
dependency4.from=Shuttle
|
||||
dependency4.to=TaxiCompany
|
||||
dependency4.type=UsesDependency
|
||||
dependency5.from=Shuttle
|
||||
dependency5.to=Location
|
||||
dependency5.type=UsesDependency
|
||||
dependency6.from=Shuttle
|
||||
dependency6.to=Passenger
|
||||
dependency6.type=UsesDependency
|
||||
dependency7.from=Demo
|
||||
dependency7.to=PassengerSource
|
||||
dependency7.type=UsesDependency
|
||||
dependency8.from=Demo
|
||||
dependency8.to=TaxiCompany
|
||||
dependency8.type=UsesDependency
|
||||
dependency9.from=TaxiCompany
|
||||
dependency9.to=Passenger
|
||||
dependency9.type=UsesDependency
|
||||
objectbench.height=76
|
||||
objectbench.width=855
|
||||
package.editor.height=513
|
||||
package.editor.width=747
|
||||
package.editor.x=70
|
||||
package.editor.y=80
|
||||
package.numDependencies=19
|
||||
package.numTargets=8
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
readme.editor.height=587
|
||||
readme.editor.width=825
|
||||
readme.editor.x=53
|
||||
readme.editor.y=23
|
||||
target1.editor.height=739
|
||||
target1.editor.width=851
|
||||
target1.editor.x=53
|
||||
target1.editor.y=60
|
||||
target1.height=50
|
||||
target1.name=Vehicle
|
||||
target1.naviview.expanded=false
|
||||
target1.showInterface=false
|
||||
target1.type=AbstractTarget
|
||||
target1.typeParameters=
|
||||
target1.width=80
|
||||
target1.x=510
|
||||
target1.y=110
|
||||
target2.editor.height=738
|
||||
target2.editor.width=834
|
||||
target2.editor.x=53
|
||||
target2.editor.y=60
|
||||
target2.height=50
|
||||
target2.name=TaxiCompany
|
||||
target2.naviview.expanded=true
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.typeParameters=
|
||||
target2.width=100
|
||||
target2.x=270
|
||||
target2.y=60
|
||||
target3.editor.height=730
|
||||
target3.editor.width=792
|
||||
target3.editor.x=53
|
||||
target3.editor.y=60
|
||||
target3.height=50
|
||||
target3.name=Demo
|
||||
target3.naviview.expanded=true
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.typeParameters=
|
||||
target3.width=80
|
||||
target3.x=50
|
||||
target3.y=130
|
||||
target4.editor.height=810
|
||||
target4.editor.width=976
|
||||
target4.editor.x=53
|
||||
target4.editor.y=23
|
||||
target4.height=50
|
||||
target4.name=Taxi
|
||||
target4.naviview.expanded=false
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.typeParameters=
|
||||
target4.width=80
|
||||
target4.x=440
|
||||
target4.y=210
|
||||
target5.editor.height=737
|
||||
target5.editor.width=839
|
||||
target5.editor.x=53
|
||||
target5.editor.y=60
|
||||
target5.height=50
|
||||
target5.name=Passenger
|
||||
target5.naviview.expanded=true
|
||||
target5.showInterface=false
|
||||
target5.type=ClassTarget
|
||||
target5.typeParameters=
|
||||
target5.width=90
|
||||
target5.x=360
|
||||
target5.y=310
|
||||
target6.editor.height=737
|
||||
target6.editor.width=837
|
||||
target6.editor.x=53
|
||||
target6.editor.y=60
|
||||
target6.height=50
|
||||
target6.name=PassengerSource
|
||||
target6.naviview.expanded=true
|
||||
target6.showInterface=false
|
||||
target6.type=ClassTarget
|
||||
target6.typeParameters=
|
||||
target6.width=130
|
||||
target6.x=120
|
||||
target6.y=230
|
||||
target7.editor.height=733
|
||||
target7.editor.width=838
|
||||
target7.editor.x=53
|
||||
target7.editor.y=60
|
||||
target7.height=50
|
||||
target7.name=Shuttle
|
||||
target7.naviview.expanded=false
|
||||
target7.showInterface=false
|
||||
target7.type=ClassTarget
|
||||
target7.typeParameters=
|
||||
target7.width=80
|
||||
target7.x=570
|
||||
target7.y=210
|
||||
target8.editor.height=737
|
||||
target8.editor.width=794
|
||||
target8.editor.x=53
|
||||
target8.editor.y=60
|
||||
target8.height=50
|
||||
target8.name=Location
|
||||
target8.naviview.expanded=true
|
||||
target8.showInterface=false
|
||||
target8.type=ClassTarget
|
||||
target8.typeParameters=
|
||||
target8.width=80
|
||||
target8.x=210
|
||||
target8.y=380
|
Reference in New Issue
Block a user