import java.text.DecimalFormat; /** * Lab #5 * CS 2334 * October 26, 2004 *

* This class models temperature. It stores temperature in Kelvin * and can convert temperatures to Celsius and Fahrenheit. *

* @author Brian F. Veale * @version 1.0 */ public class Temperature { /** The temperature stored in Kelvin. */ float tempKelvin; /** * This initializes the temperature to 0 degrees Kelvin. */ public Temperature() { tempKelvin = 0.0F; } /** * This method returns the temperature in Kelvin as a String. *

* @return The temperature as a String in Kelvin. */ public String getKelvin() { DecimalFormat formatter = new DecimalFormat( "###.##" ); return formatter.format( tempKelvin ); } /** * This method returns the temperature in Celsius as a String. *

* @return The temperature as a String in Celsius. */ public String getCelsius() { DecimalFormat formatter = new DecimalFormat( "###.##" ); float temp = tempKelvin - 273.15F; return formatter.format( temp ); } /** * This method returns the temperature in Fahrenheit as a String. *

* @return The temperature as a String in Fahrenheit. */ public String getFahrenheit() { DecimalFormat formatter = new DecimalFormat( "###.##" ); float temp = tempKelvin * 1.8F - 459.67F; return formatter.format( temp ); } /** * This method sets the temperature. The temperature passed * in is in Fahrenheit and is converted into Kelvin. *

* @param temp The temperature in Fahrenheit. */ public void setFahrenheit( float temp ) { tempKelvin = (temp + 459.67F) / 1.8F; } }