//CS5-HMC-Sp.,00-HW3-4 //A. Khakpour, May, 00 import java.text.*; class MilesPerGallon { //----------------------------------------------------------------- // Computes the miles per gallon achieved given the gallons used // and the odometer readings. //----------------------------------------------------------------- public static void main (String[] args) { float gas, mpg; int odometer1, odometer2; System.out.print ("Enter the gas used: "); gas = Keyboard.readFloat(); System.out.print ("Initial odometer reading: "); odometer1 = Keyboard.readInt(); System.out.print ("Final odometer reading: "); odometer2 = Keyboard.readInt(); mpg = (odometer2 - odometer1) / gas; DecimalFormat fmt = new DecimalFormat ("0.##"); System.out.println ("Miles Per Gallon: " + fmt.format(mpg)); } }