Fleet's fillUp() Method

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

Answer:

Since there are two cars in the Fleet, there should be an odometer reading and a number of gallons for each car's fillUp().

Fleet's fillUp() Method

Assume that at the end of a week each car in the Fleet is filled with gasoline and its new odometer reading is noted. The fillUp() method for Fleet will get this data. The first two parameters will be for the town car and the last two will be for the sports utility vehicle.

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

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

  // method
  double calculateMPG()
  {
    double sumMPG; 
    sumMPG = town.calculateMPG() + suv.calculateMPG() ;
    return sumMPG/2.0;
  }

  void fillUp( int townOdo, double townGal, int suvOdo, double suvGal )
  {

    town.fillUp(  ,  );

    suv .fillUp(  ,  );
  }
}

Of course the Fleet.fillUp() method is written in terms of the Car.fillUp() method.

QUESTION 14:

Fill up the blanks.