Constructor for Fleet

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page
  1. The first car in the fleet has odometer readings of 1000, 1234, and gallons of 10
  2. The second car in the fleet has odometer readings of 777, 999, and gallons of 20

Answer:

class FleetTester
{
  public static void main ( String[] args)
  {
    Fleet myCars = new Fleet( 1000, 1234, 10, 777, 999, 20  );
  }
}

Constructor for Fleet

In this program, the cars that make up a fleet are constructed when the fleet is constructed. Here is the program with some additional work:

class Fleet
{
  // data
  Car town;
  Car suv;

  // constructor
  Fleet( int start1, int end1, double gal1, 
         int start2, int end2, double gal2 )
  {
    town =  ;
    suv  =  ;
  }

  // method

}

class Car
{
  . . . .

  Car(  int first, int last, double gals  )
  {
    . . . .
  }
}

class FleetTester
{
  public static void main ( String[] args)
  {
    Fleet myCars = new Fleet( 1000, 1234, 10, 777, 999, 20 );
  }

}

QUESTION 6:

Fill in the blanks in the constructor for Fleet. It should construct each of the two cars.