Java Reference
In-Depth Information
Exercise 14.17 Critically assess the list of steps we have outlined, with the following ques-
tions in mind. Do you feel the order is appropriate? Is the level of complexity of each too high,
too low, or just right? Are there any steps missing? Revise the list as you see fit, to suit your
own view of the project.
Exercise 14.18 Are the completion criteria (tests on completion) for each stage sufficiently
obvious? If so, document some tests for each.
A first stage
For the first stage, we want to be able to create a single passenger, have them picked up by a
single taxi, and have them delivered to their destination. This means that we shall have to work
on a number of different classes: Location , Taxi , and TaxiCompany , for certain, and pos-
sibly others. In addition, we shall have to arrange for simulated time to pass as the taxi moves
within the city. This suggests that we might be able to reuse some of the ideas involving actors
that we saw in Chapter 10.
The taxi-company-stage-one project contains an implementation of the requirements of this first
stage. The classes have been developed to the point where a taxi picks up and delivers a pas-
senger to their destination. The run method of the Demo class plays out this scenario. However,
more important at this stage are really the test classes— LocationTest , PassengerTest ,
PassengerSourceTest , and TaxiTest —which we discuss in Section 14.4.3.
Rather than discuss this project in detail, we shall simply describe here some of the issues that
arose from its development out of the previous outline version. You should supplement this
discussion with a thorough reading of the source code.
The goals of the first stage were deliberately set to be quite modest yet still relevant to the fun-
damental activity of the application—collecting and delivering passengers. There were good
reasons for this. By setting a modest goal, the task seemed achievable within a reasonably short
time. By setting a relevant goal, the task was clearly taking us closer toward completing the
overall project. Such factors help to keep our motivation high.
We have borrowed the concept of actors from the foxes-and-rabbits project of Chapter 10. For this
stage, only taxis needed to be actors, through their Vehicle superclass. At each step a taxi either
moves toward a target location or remains idle (Code 14.2). Although we did not have to record
any statistics at this stage, it was simple and convenient to have vehicles record a count of the
number of steps for which they are idle. This anticipated part of the work of one of the later stages.
Code 14.2
The Taxi class as
an actor
* A taxi is able to carry a single passenger.
* @author David J. Barnes and Michael Kölling
* @version 2011.07.31
Search WWH ::

Custom Search