go to previous page   go to home page   go to next page

Answer:

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

Think about the classes you need before you start writing. This makes programming easier and your programs will have fewer bugs. Object oriented design means deciding what classes you need, what data the objects hold, and how the objects will behave. Let us do that with the Car class.


Car

A class that calculates miles per gallon.

Variables

Constructors

Methods


Look at the parameter list for the constructor:

Car( double startOdo, double endingOdo, double gallons );

This says that the constructor must be called with three items of data: three double precision values.

QUESTION 2:

Could a main() method create a Car object?