Java Reference
In-Depth Information
Figure 14.2
A visualization of
the city
■
A
Simulation
class now manages the actors, much as it did in the
foxes-and-rabbits
project
. The actors are the vehicles, the passenger source, and a GUI provided by the
CityGUI
class. After each step, the simulation pauses for a brief period so that the GUI does
not change too quickly.
■
The need for something like the
City
class was identified during development of stage one.
The
City
object defines the dimensions of the city's grid and holds a collection of all the
items of interest that are in the city—the vehicles and the passengers.
■
Items in the city may optionally implement the
DrawableItem
interface, which allows
the GUI to display them. Images of vehicles and people are provided in the
images
folder
within the project folder for this purpose.
■
The Taxi class implements the
DrawableItem
interface. It returns alternative images to the
GUI, depending on whether it is occupied or empty. Image files exist in the
images
folder
for a shuttle to do the same.
■
The
PassengerSource
class has been refactored significantly from the previous version, to
better fit its role as an actor. In addition, it maintains a count of missed pickups for statistical
analysis.
■
The
TaxiCompany
class is responsible for creating the taxis to be used in the simulation.
As you explore the source code of the
taxi-company-later-stage
project, you will find illus-
trations of many of the topics we have covered in the second half of this topic: inheritance,
polymorphism, abstract classes, interfaces, and error handling.
Search WWH ::
Custom Search