Finished Program

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

The complete program is given below.

Finished Program

Here is the complete main(). Unfortunately, until you write the code for Car the program can't be run.

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( startMiles, endMiles, gallons  );

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

QUESTION 4:

We still need a definition for class Car. Can a programmer write a definition for the class Car?