Java project Taxi fleet

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
  2. 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.
  3. 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.
  4. Define a toString() method that can be used to facilitate the testing of the class.
  5. Define an update method with appropriate parameters that will be used to update the
    information of the taxi after each trip it completes.
  6. Define a reset method that will be used to reset the values of distance and trips
    each time the taxi is serviced.
  7. 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.

  1. Define the constructor for class Fleet.
  2. 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.)
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. Define a method called display() which prints out the contents of the array to the screen

Firstly, welcome to the forums.

While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too. Some of what you are asking is pretty trivial in the Free Code Camp context, so you might find that if you’re not getting the instruction and material you need in your current studies, the FCC curriculum will really help you get started. At a modest guess I’d say investing a 4-5 hours working through the curriculum here will really pay off. You can find the curriculum at https://www.freecodecamp.org/learn.

With your current questions, we don’t have enough context to know what you already know or don’t know, so it is impossible to guide you without just telling you the answer (which we won’t do).

It is pretty typical on here for people to share a codepen / repl.it / jsfiddle example of what they have tried so that anyone helping has more of an idea of what help is actually helpful.

Please provide some example of what you’ve tried and I’m sure you’ll get more help.

Happy coding :slight_smile:

This is what i got what i got for the taxi class

public class Taxi
{
   private String name;
   private double mileage;
   private int trips;
   private double kmtraveled;


      //constructor
      public Taxi(String name)
      {
         this.name = name;
      }
	public void update()
      {
         trips = trips++;
         mileage = mileage + kmtraveled;

         //return trips;
         //return (int)mileage;
      }

      public void reset()
      {
         trips = 0;
         mileage = 0;
      }

      public String getName()
      {
         return name;
      }

      public double getMileage()
      {
         return mileage;
      }


      public int getTrips();
      {
         return trips;
      }

      public String toString()
      {
         return " name "+name+" mileage " +mileage+ " trips " + trips;

      }


}

This is showing some erroros if someone can help me guide with the mistakes .

you have a semi-colon in the getTrips method

change it to

public int getTrips()
      {
         return trips;
      }

Should take care of the error

There ae so many errors in your code.
Initialization is not done properly, getter methods do not return the actual class variables, etc.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.