Samantha Sunshine owns a fleet of bright yellow solar-powered taxi cars. She also owns a
small garage where only one taxi can be checked or serviced at a time. Each taxi is identified
by a name (such as Solar Wind) chosen by Samantha. She has asked you to write a program
to manage information kept on her taxis. As part of the project, your task is to design and
implement two classes:
- Class Taxi to represent a taxi
- Class Fleet to represent the taxi fleet.
Each taxi has a name, the number of kilometers the taxi has travelled since its last service,
and the number of trips it has done since its last service. The data kept on a taxi is updated
as soon as it returns from a trip.
Definition of class Taxi
Based on the above information, it is decided that class Taxi is to have three attributes
declared as follows:
private String name;
private double distance;
private int trips;
where distance is the number of kilometers travelled since last service. - Define the constructor for the class. The constructor should take only one argument,
the name of the taxi. Explicitly initialise the other attributes to 0. - Define a toString() method that can be used to facilitate the testing of the class.
- Define an update method with appropriate parameters that will be used to update the
information of the taxi after each trip it completes. - Define a reset method that will be used to reset the values of distance and trips
each time the taxi is serviced. - Define all the get methods.
Definition of Class Fleet
Assume that class Taxi has been developed and thoroughly tested. You are now in a
position to develop class Fleet. This class stores and manages information about the fleet of
taxis. Functionality provided by this class should include methods to do the following:
• Add a taxi to the fleet
• Remove a taxi from the fleet
• Update the information about a particular taxi
• Reset the number of trips and the distance travelled for a particular taxi
• Determine the taxi to service next (see more information below).
You are told that the fleet is not expected to have more than 50 taxis. Using this information,
the attributes for class Fleet are declared as follows:
public static final int MAX_FLEET_SIZE = 50;
private Taxi taxis;
private int taxiCount;
where taxiCount is the number of taxis in the current fleet.
- Define the constructor for class Fleet.
- Define method search(String name)
This method takes as argument the name of the taxi to search for. If a taxi with that
name is found, the method should return the index of the taxi. Otherwise, it should
return -1.
(This method will be used by other methods of the class, for example, the addTaxi()
that is defined next.) - Define method addTaxi(String name)
This method takes as an argument the name of the new taxi. It should check if the taxi
already exists (make use of the method search described above) and if so, return false.
Otherwise add the taxi to the fleet and return true. - Define a method to delete a taxi of a given name from the fleet. If the taxi exists, delete
it and return true, otherwise return false. - Define a method to update the information about a taxi of a given name after it has
completed a trip. The method will need parameters containing the information to do the
updates. Return true if the taxi existed, false otherwise. - Define a method to reset the number of trips and the distance travelled for a taxi of a
given name. Return true if the taxi existed, false otherwise. - Define a method to determine the taxi to service next.
As the garage can only service one taxi at a time, the taxi with the highest value of
distance since its last service will be chosen for the next service. In cases of ties, any
one of the tied taxis can be chosen. The method should return the name of the taxi to
be serviced next. - Define a method called display() which prints out the contents of the array to the screen