Two Cars

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:

Sure.

Two Cars

Here is the program with a few more blank lines:


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

    System.out.println( "Miles per gallon of car 2 is " + car2.calculateMPG() );

  }
}

QUESTION 12:

Fill in the blanks for the second car, which has

  • A starting odometer reading of 100000
  • An ending odometer reading of 100300
  • Gas consumption of 12.5 gallons.