Answer:

import Car ;

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() );
  }
}

Collecting Input from the User

With the documentation for Car already done, writing the program is easy. (However you can't run this program yet because class Car has not yet been defined.) Adding user interaction is done just as in previous programs. All input values are double precision.

import java.util.Scanner ;
import Car;

class MilesPerGallon
{
  public static void main( String[] args ) 
  {
    Scanner scan = new Scanner(System.in);

    double startMiles, endMiles, gallons;

    System.out.print("Enter first reading: " ); 
    startMiles = scan.nextDouble();

    System.out.print("Enter second reading: " ); 
    endMiles = scan.nextDouble();

    System.out.print("Enter gallons: " ); 
    gallons  = scan.nextDouble();

    Car car = new Car( , ,   );

    System.out.println( "Miles per gallon is "  + car.calculateMPG() );
  }
}

 

QUESTION 4:

Fill in the blanks so that the program has user interaction.