Can a programmer write a definition for the class Car?
Of course!
Here is the miles per gallon program. To keep the program short, user interaction has been left out.
class Car
{
// instance variables
// constructor
// 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() );
}
}
The source file must be named
MilesPerGallon.java after the name of
the class that contains main().
Decide what variables should go in the data section. Look back to the Car class for the class to see what you need.