Java Reference
In-Depth Information
Exercise 14.23 If you see any problems with the current way in which vehicle:passenger asso-
ciations are stored, would creating a unique identification for each association help—say a “booking
number”? If so, would any of the existing method signatures in the Vehicle hierarchy need to be
changed? Implement an improved version that supports the requirements of all existing scenarios.
Testing the first stage
As part of the implementation of the first stage, we have developed two test classes: LocationTest
and TaxiTest . The first checks basic functionality of the Location class that is crucial to correct
movement of vehicles. The second is designed to test that a passenger is picked up and delivered
to their destination in the correct number of steps and that the taxi becomes free again immediately
afterwards. In order to develop the second set of tests, the Location class was enhanced with the
distance method, to provide the number of steps required to move between two locations. 1
In normal operation, the application runs silently, and without a GUI there is no visual way to
monitor the progress of a taxi. One approach would be to add print statements to the core meth-
ods of classes such as Taxi and TaxiCompany . However, BlueJ does offer the alternative of
setting a breakpoint within the act method of, say, the Taxi class. This would make it possible
to “observe” the movement of a taxi by inspection.
Having reached a reasonable level of confidence in the current state of the implementation,
we have simply left print statements in the notification methods of TaxiCompany to provide a
minimum of user feedback.
As testimony to the value of developing tests alongside implementation, it is worth recording
that the existing test classes enabled us to identify and correct two serious errors in our code.
Exercise 14.24 Review the tests implemented in the test classes of taxi-company-stage-
one . Should it be possible to use these as regression tests during the next stages, or would
they require substantial changes?
Exercise 14.25 Implement additional tests and further test classes that you feel are nec-
essary to increase your level of confidence in the current implementation. Fix any errors you
discover in the process of doing this.
A later stage of development
It is not our intention to discuss in full the completion of the development of the taxi company
application, as there would be little for you to gain from that. Instead, we shall briefly present
the application at a later stage, and we encourage you to complete the rest from there.
This more advanced stage can be found in the taxi-company-later-stage project. It handles multiple
taxis and passengers, and a GUI provides a progressive view of the movements of both (Figure 14.2).
Here is an outline of some of the major developments in this version from the previous one.
We anticipate that this will have an extended use later in the development of the application as it should
enable the company to schedule vehicles on the basis of which is closest to the pickup point.
Search WWH ::

Custom Search