/** * Converts Fahrenheit to Celsius and from miles per hour to km per hour * * Illustrates * - Using parenthesis to enforce order of operations * - Division with floating point numbers * - Using final keyword for mathematical constants * * @author alchambers */ public class Conversions{ public static void main(String[] args){ // The equation for converting fahrenheit to celsius: // C = (F - 32) * 5/9 final int FREEZING_POINT = 32; final double CONVERSION_RATIO = 5.0/9.0; double fahrenheit = 50.0; double celsius = (fahrenheit - FREEZING_POINT) * CONVERSION_RATIO; System.out.println(fahrenheit + " degrees fahrenheit equals " + celsius + " degrees celsius"); // The conversion factor between mph and km/h is // 1 mph = 1.60935 km/h final double CONVERSION_FACTOR = 1.60935; double milesPerHour = 60.0; double kmPerHour = milesPerHour * CONVERSION_FACTOR; System.out.println(milesPerHour + " mph in kilometers is " + kmPerHour + " km/h"); } }