// Helene Martin, CSE 142 // Prints out temperatures in farenheight and celcius rounded to two digits. // goal: demonstrates methods that return. public class ReturnDemo { public static void main(String[] args) { double nowTemp = 50.6; double tomorrowTemp = 72; double nowTempC = fToC(nowTemp); System.out.println("It's currently " + nowTemp + "F (" + round2(nowTempC) + "C)"); System.out.println("Tomorrow, it will be " + tomorrowTemp + "F (" + round2(fToC(tomorrowTemp)) + "C)"); System.out.println(round(234.2446442, 3)); } // Converts a temperature in farenheight to celcius. public static double fToC(double tempF) { double tempC = 5.0 / 9.0 * (tempF - 32); return tempC; } // Rounds a value to two digits after the decimal point. public static double round2(double val) { return (double)Math.round(val * 100) / 100; } // Rounds a value to a given number of digits after the decimal point. public static double round(double val, int digits) { return (double)Math.round(val * Math.pow(10, digits)) / Math.pow(10, digits); } // Calculates the displacement of an object with initial velocity v0 at time t // given an acceleration a. public static double displacement(double v0, double t, double a) { return v0 * t + (a * Math.pow(t, 2)) / 2; } }