Skip to Main Content

Java Programming


For appeals, questions and feedback, please email

Q1. how you solve this

User_DWJZRMay 22 2021

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: (1) Class Taxi to represent a taxi, and (2) Fleet to represent the taxi fleet. Each taxi has a name, the number of kilometers the taxi has traveled 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 mileage; private int trips; where mileage is the number of kilometers traveled since last service. a) Define the constructor for the class. The constructor should take only one argument, the name of the taxi. b) Define the toString method that can be used to facilitate the testing of the class. c) Define the update method that will be used to update the information of the taxi after each trip it completes. d) Define the reset method that will be used to reset the values of mileage and trips each time the taxi is serviced. e) 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 ? To reset the number of trips and the number of kilometers traveled 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 MAX_FLEET_SIZE = 50; private Taxi [] taxis; private int taxiCount; where taxiCount is the number of taxis in the current fleet. f) Define the constructor for class Fleet. g) 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.) h) Define method addTaxi( String name ). This method takes as an argument the name of the new taxi and adds the taxi to the fleet. It should check that the name is indeed new. To do this, it should make use of the method search described above. [4 marks] i) Define a method to delete a taxi from the fleet. [4 marks] j) Define a method to update the information about a particular taxi [4 marks] k) Define a method to reset the number of trips and the number of kilometers traveled for a particular taxi. [4 marks] l) 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 mileage since its last service will be chosen for the next service. In cases of ties, one of the taxis will be chosen. The method should return the name of the taxi to be serviced next. [4 marks]

Post Details
Added on May 22 2021
1 comment