/** An instance represents a temperature in Farenheit and Celsius */ public class Temperature { private double farenheit; // F measurement; = 9*C/5+32, >= -459.67 private double celsius; // C measurement; = 5*(F-32)/9, >= -273.15 /** * Constructor: Create a new temperature value with * t farenheit and 5*(t-32)/9 Celsius * Precondition: t >= -459.67 (absolute zero temperature) */ public Temperature(double t) { farenheit = t; celsius = 5.0*(t-32)/9.0; } /** * Constructor: Create a new temperature value at * the freezing point of water. */ public Temperature() { this(32); } /** * Sets the farenheit (and adjusts the celsius to match) * Precondition: t >= -459.67 (absolute zero) */ public void setFarenheit(double t) { farenheit = t; celsius = 5.0*(t-32)/9.0; } /** * 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) { celsius = t; farenheit = 9.0*t/5.0+32; } /** * Yields: the temperature in celsius */ public double getCelsius() { return celsius; } /** * Yields: a string representation of this temperature */ public String toString() { return farenheit+"¡F ("+celsius+"¡C)"; } /** * Yields: "o is a Temperature of the same value" */ public boolean equals(Object o) { if (!(o instanceof Temperature)) { return false; } Temperature t = (Temperature)o; return t.farenheit == farenheit && t.celsius == celsius; } }