/**
 * An encapsulation of a very simple immutable Temperature class/enum
 * hybrid.
 *
 * Note: For simplicity, Temperature objects do not have an associated
 * scale (e.g., Farenheit, Celsius/Centigrade, or Kelvin).
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class Temperature
{
    private double    value;
    private String    stringValue;
    
    public static final Temperature    OFF = new Temperature();    

    /**
     * Construct a Temperature object with a stringValue of "Off"
     */
    private Temperature()
    {
       stringValue = "Off   ";
    }

    /**
     * Explicit Value Constructor.
     *
     * @param value   The value of this Temperature
     */
    public Temperature(double value)
    {
       this.value = value;

       // Since objects in this class are immutable, it makes sense to
       // create the String representation now
       stringValue = String.format("%-6.1f", this.value);
    }

    /**
     * Return true if and only if this Temperature objects
     * has the same value as the given Temperature object.
     *
     * @param other   The Temperature of interest
     */
    public boolean equals(Temperature other)
    {
        return stringValue.equals(other.stringValue);
    }
    
    /**
     * Return a String representation of this Temperature
     *
     * @return   The String representation
     */
    public String toString()
    {
       return stringValue;       
    }
}
