A good answer might be:

You would expect to use:

  1. Starting odometer reading,
  2. Ending odometer reading, and
  3. Gallons of gas used between the readings.

Specifications for the Car class

Professional programmers carefully design the classes they need before any coding is done. With well-designed classes programming is much easier and the program has fewer bugs. Object oriented design consists of deciding what classes are needed, what data they will hold, and how they will behave. All these decisions are documented (written up) and then examined. If something doesn't look right, it is fixed before any programming is done. Let us do that with our Car class.


Car

A class that calculates miles per gallon.

Variables

  • int startMiles;      // Starting odometer reading
  • int endMiles;       // Ending odometer reading
  • double gallons;         // Gallons of gas used between the readings

Constructors

  • Car( int startOdo, int endingOdo, double gallons )
    • Creates a new instance of a Car object with the starting and ending odometer readings and the number of gallons of gas consumed.
Methods
  • double calculateMPG()
    • calculates and returns the miles per gallon for the car.

Look at the parameter list for the constructor:

int startOdo, int endingOdo, double gallons
This says that the constructor must be called with three items of data: an int, another int, and a double. The items must occur in that order.

QUESTION 2:

Could a main() method create a Car object?

Click Here after you have answered the question