
/**
 *
 * Class for temperature conversion (Celsius, Fahrenheit)
 *
 */

public class Temperature
    {
    private double celsius, fahr;

    // Temperature Constructor

    public Temperature ()
	{
	setCelsius(0.0);
	celsiusToFahr();
	} // end of constructor method

    // selector methods for Temperature instance fields

    public double getCelsius()
	{
	return celsius ;
	} // end of method getCelsius

    public double getFahr()
	{
	return fahr ;
	} // end of method getFahr

    // mutator methods for Temperature instance fields

    private void celsiusToFahr()
	{
	fahr = (double) (1.8 * celsius + 32);
	} // end of method celsiusToFahr

    public void setCelsius(double c)
	{
	celsius = c;
	celsiusToFahr();
	} // end of method setCelsius

    private void fahrToCelsius()
	{
	celsius = (double) (5.0 * (fahr - 32.0) / 9.0);
	} // end of method fahrToCelsius

    public void setFahr(double f)
	{
	fahr = f ;
	fahrToCelsius();
	} // end of method setFahr

    // standard "toString" method

    public String toString()
	{
	return celsius + " degrees celsius " + 
		fahr + " degrees Fahrenheit"; 
	} // end of method toString

    } // end of class Temperature


