Easy. The filled in program is below.
In this program, two defferent Car
objects are constructed,
each with different data,
and the miles per gallon calculation is performed on each.
import java.io.* ; class Car { . . . . } class MilesPerGallon { public static void main( String[] args ) { Car car1 = new Car( 32456, 32810, 10.6 ); System.out.println( "Miles per gallon of car 1 is " + car1.calculateMPG() ); Car car2 = new Car( 100000, 100300, 10.6 ); System.out.println( "Miles per gallon of car 2 is " + car2.calculateMPG() ); } }
The picture shows the situation just after the second object has been constructed:
Notice that there is one class definition, two objects, and one static main()
.