//File: Temperature.java import CSLib.*; public class Temperature { // Convert temperature from Fahrenheit to Centigrade // Author: Samuel N. Kamin, June 1, l996 public void compute () { double temperature; // The Fahrenheit temperature. InputBox in; OutputBox out; in = new InputBox(); in.setPrompt ("Please type the temperature (deg F): "); temperature = in.readDouble(); out = new OutputBox(); //The following illustrates how to use control charactrers to format output. //Within a string, a backward slash \ has special meaning. //The very next character following a \ is a control character; i.e., //it tells the computer something about how to format the output. //Ex. \t => tab \n => new line out.println ("\tDegrees Fahrenheit\t\tDegrees Celcius\n\n\n\n"); out.println (""); //Create a new memory location in which to store the converted Fahrenheit temperature double celcius = 5.0 * (temperature - 32.0) / 9.0; out.println ("\t" + temperature + "\t\t\t\t" + celcius); //The use of the string concatenation operator + allows us to say //in one line using the println() method what previously took several lines // using the print() method. The following code has been condensed to the //one line above. //out.print(temperature); //out.print(" deg F is "); //out.print((5.0 * (temperature - 32.0) / 9.0)); //out.print(" deg C."); } }