/** * Demonstrates declaring and calling a method * @author Pete Nordquist * @version 100127 */ public class W04N02 { /** * @param ft - temperature in Fahrenheit * @return - temperature in Celcius */ public static double getCelsiusFor(double ft) { return 5.0/9*(ft - 32.0); } /** * @param num - number to raise to a power * @param toRaiseTo - power to which to raise num * @return - result of raising num to the toRaiseTo power */ public static double raiseToPower(double num, double toRaiseTo) { // the Math class has the method we need to do this job double returnValue; returnValue = Math.pow(num, toRaiseTo); return returnValue; } // main program public static void main(String[] args) { double temp; temp = IO.readDouble("Your temp> "); // call getCelsiusfor() to convert our temp to Celcius // check temperature to see if it is above freezing // (zero degrees in Celcius) if (getCelsiusFor(temp) > 0.0) { System.out.println("above freezing"); } else { System.out.println("freezing or below"); } // get two numbers from the user double d1; double d2; double rslt; d1 = IO.readDouble("Double #1? "); d2 = IO.readDouble("Double #2? "); // call raiseToPower rslt = raiseToPower(d1, d2); // print the result System.out.println(rslt); } }