class TempConverter2 { static double fahrToCelc( double tempF ) { return (tempF - FAHR_FREEZING) * CELC_PER_FAHR; } static double FAHR_FREEZING = 32.0; static double FAHR_BOILING = 212.0; static double CELC_PER_FAHR = 100.0 / (FAHR_BOILING - FAHR_FREEZING); static void testInteractive() { java.util.Scanner s; // Declare a variable. /* make a new Scanner which reads from the keyboard (System.in): */ s = new java.util.Scanner( System.in ); System.out.print( "What is your name? " ); String usersName; usersName = s.next(); double temperature; System.out.print( "Please enter a temperature in Fahrenheit: " ); temperature = s.nextDouble(); System.out.println( "Hi " + usersName + "; " + temperature + "F = " + fahrToCelc(temperature) + "C." ); System.out.print( "Please enter a temperature in Fahrenheit: " ); temperature = s.nextDouble(); System.out.println( "Hi " + usersName + "; " + temperature + "F = " + fahrToCelc(temperature) + "C." ); System.out.print( "Please enter a temperature in Fahrenheit: " ); temperature = s.nextDouble(); System.out.println( "Hi " + usersName + "; " + temperature + "F = " + fahrToCelc(temperature) + "C." ); System.out.println( "Have you ever noticed, " + usersName + ",\n" + "that everybody complains about the weather,\n" + "but nobody does anything about it?" ); // Quote by Mark Twain. // Note: No return value, from this function -- // printing results to the console means they're gone forever, // and we can't pass those strings to other methods for further // processing; we'd need to *return* the string for that. } static void testTempConverter2() { System.out.println( "Actual: " + fahrToCelc(32) ); System.out.println( "Expect: " + 0.0 ); System.out.println( "Actual: " + fahrToCelc(212) ); System.out.println( "Expect: " + 100.0 ); System.out.println( "Actual: " + fahrToCelc(-40) ); System.out.println( "Expect: " + -40.0 ); System.out.println( "Actual: " + fahrToCelc(98.6) ); System.out.println( "Expect: " + 37.0 ); } }