/** An instance represents a temperature in Farenheit and Celsius 
  * This has the same interface as temperature, but now only has
  * one field instead of two.
  */
public class BetterTemperature {

    private double farenheit; // F measurement; >= -459.67
    
    /** 
     * Constructor: Create a new temperature value with 
     * t farenheit and 5*(t-32)/9 Celsius
     * Precondition: t >= -459.67 (absolute zero)
     */
    public BetterTemperature(double t) {
        farenheit = t;
    }

    /** 
     * Constructor: Create a new temperature value at 
     * the freezing point of water.
     */
    public BetterTemperature() {
        this(32);
    }

    /**
     * Sets the farenheit (and adjusts the celsius to match)
     * Precondition: t >= -459.67 (absolute zero)
     */
    public void setFarenheit(double t) {
        farenheit = t;
    }
    
    /**
     * Yields: the temperature in farenheit
     */
    public double getFarenheit() {
        return farenheit;
    }
    
    /**
     * Sets the celsius (and adjusts the farenheit to match)
     * Precondition: t >= -273.15 (absolute zero)
     */
    public void setCelsius(double t) {
        farenheit = 9.0*t/5.0+32;
    }
    
    /**
     * Yields: the temperature in celsius
     */
    public double getCelsius() {
        return 5.0*(farenheit-32)/9.0;
    }
    
    /**
     * Yields: a string representation of this temperature
     */
    public String toString() {
        return getFarenheit()+"�F ("+getCelsius()+"�C)";
    }
    
    /**
     * Yields: "o is a Temperature of the same value"
     */
    public boolean equals(Object o) {
        if (!(o instanceof BetterTemperature)) {
            return false;
        }
        
        BetterTemperature t = (BetterTemperature)o;
        return t.farenheit == farenheit;
    }
    
}