A good answer might be:

The completed parameter list is seen below.

Initializing the Data

In this class, the parameter list uses three parameters to match the three instance variables that will be initialized.

import java.io.* ;

class Car
{
  // instance variables
  int startMiles;   // Stating odometer reading
  int endMiles;     // Ending odometer reading
  double gallons;   // Gallons of gas used between the readings

  // constructor
  Car( int first, int last, double gals )
  {

    __________ = __________;
    __________ = __________;
    __________ = __________;

  }

  // methods

}

class MilesPerGallon
{
  public static void main( String[] args ) 
  {
    Car car = new Car( 32456, 32810, 10.6 );
    System.out.println( "Miles per gallon is " + car.calculateMPG() );
  }
}

Note: In most classes there is NOT an exact match between the parameters of a constructor and the instance variables. The parameters in the list do not have to be in the same order as the instance variables (although doing this might help you, the compiler does not care.) Also, there may be fewer (or more) parameters than instance variables.


QUESTION 9:

Now fill in the assignment statements to complete the constructor.