Computer Science 523
Advanced Programming
Summer 2014, The College of Saint Rose
MilesPerGallon BlueJ Project
Click here to download a BlueJ project for MilesPerGallon.
MilesPerGallon Source Code
The Java source code for MilesPerGallon is below. Click on a file name to download it.
/** * Compute miles per gallon from input. * * Develped in CSC 202. Fall 2012. The College of Saint Rose * @author Jim Teresco * 9/11/12 * * $Id: MilesPerGallon.java 2366 2014-05-20 02:33:22Z terescoj $ * */ import java.util.Scanner; public class MilesPerGallon { public static void main(String args[]) { Scanner numInput = new Scanner(System.in); // read miles System.out.print("How many miles did you drive? "); double miles = numInput.nextDouble(); // read gallons System.out.print("How many gallons of gas did you use? "); double gallons = numInput.nextDouble(); // compute mpg double mpg = miles / gallons; // report result System.out.println("Your MPG is " + mpg); } }