Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class MileageCalc {
  4.    public double convKilometersToMiles(double numKm) {
  5.       double milesPerKm = 0.621371;
  6.       return numKm * milesPerKm;
  7.    }
  8.  
  9.    public double convLitersToGallons(double numLiters) {
  10.      double litersPerGal = 0.264172;
  11.      return numLiters * litersPerGal;
  12.   }
  13.  
  14.    public double calcMpg(double distMiles, double gasGallons) {
  15.       System.out.println("FIXME: Calculate MPG");
  16.       return 0.0;
  17.    }
  18.  
  19.    public static void main(String[] args) {
  20.       Scanner scnr = new Scanner(System.in);
  21.       double distKm;
  22.       double distMiles;
  23.       double gasLiters;
  24.       double gasGal;
  25.       double userMpg;
  26.       MileageCalc tripOdometer = new MileageCalc();
  27.    
  28.       System.out.println("Enter kilometers driven: ");
  29.       distKm = scnr.nextDouble();
  30.       System.out.println("Enter liters of gas consumed: ");
  31.       gasLiters = scnr.nextDouble();
  32.    
  33.       distMiles = tripOdometer.convKilometersToMiles(distKm);
  34.       gasGal = tripOdometer.convLitersToGallons(gasLiters);
  35.       userMpg = tripOdometer.calcMpg(distMiles, gasGal);
  36.    
  37.       System.out.println("Miles driven: " + distMiles);
  38.       System.out.println("Gallons of gas: " + gasGal);
  39.       System.out.println("Mileage: " + userMpg + " mpg");
  40.    }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement