package cse1030; /** * A simple utility class for converting US fuel economy values to metric fuel * consumption values. * * @author CSE1030Z * */ public class FuelEfficiency { /** * The number of litres in one US gallon. */ public static final double LITRES_PER_GALLON = 3.785411784; /** * Converts US fuel economy (in miles per US gallon) to metric fuel * consumption (in litres per 100 km). * * @param mpg * The fuel economy in miles per US gallon. * @return The fuel consumption in litres per 100 km. */ public static double toLitresPerHundredkm(double mpg) { double kmPerGallon = DistanceUtility.milesToKilometres(mpg); double gallonsPerHundredkm = 100.0 / kmPerGallon; return gallonsPerHundredkm * LITRES_PER_GALLON; } private FuelEfficiency() { // private to prevent instantiation } }