|
Temperatures |
|
1 // joi/2/linear/Temperatures.java 2 // 3 // 4 // Copyright 2003 Bill Campbell and Ethan Bolker 5 6 /** 7 * Temperature conversion program, 8 * for exercising LinearEquation objects. 9 * 10 * @version 2 11 */ 12 13 public class Temperatures 14 { 15 /** 16 * First a hardcoded test of Celsius-Fahrenheit conversion, 17 * then a loop allowing the user to test interactively. 18 */ 19 20 public static void main( String[] args ) 21 { 22 Terminal terminal = new Terminal(); 23 24 // create a Celsius to Fahrenheit converter 25 LinearEquation c2f = new LinearEquation( 9.0/5.0, 32.0 ); 26 27 // ask it to tell us its inverse, for F to C 28 LinearEquation f2c = c2f.getInverse(); 29 30 /////////////////////////////////////////////////// 31 // Testing style 1: Hard coded, self-documenting // 32 /////////////////////////////////////////////////// 33 34 terminal.println( "Hard coded self documenting tests:" ); 35 terminal.print( "c2f.compute( 0.0 ), should see 32.0: "); 36 terminal.println( c2f.compute( 0.0 ) ); 37 terminal.print( "f2c.compute( 212.0 ), should see 100.0: "); 38 terminal.println( f2c.compute( 212.0 ) ); 39 40 ////////////////////////////////// 41 // Testing style 2: Interactive // 42 ////////////////////////////////// 43 44 terminal.println(); 45 terminal.println( "Interactive tests:" ); 46 while ( terminal.readYesOrNo("more?") ) { 47 double degreesCelsius = 48 terminal.readDouble( "Celsius: " ); 49 terminal.println(" = " 50 + c2f.compute( degreesCelsius ) 51 + " degrees Fahrenheit" ); 52 double degreesFahrenheit = 53 terminal.readDouble( "degrees Fahrenheit: " ); 54 terminal.println(" = " 55 + f2c.compute( degreesFahrenheit ) 56 + " degrees Celsius" ); 57 } 58 } 59 } 60
|
Temperatures |
|