/* Temperature2.java (child class of Temperature) ** An instance of this class has all the capabilities of an instance of its ** parent class, but in addition supports expressing temperatures (and ** temperature changes) in terms of Fahrenheit degrees. */ public class Temperature2 extends Temperature { // constructor // ----------- /* Initializes this Temperature to be the specified # of degrees, ** where that measure is to be interpreted as on the Celsius scale if ** the 2nd parameter is true but on the Fahrenheit scale if it is false. */ public Temperature2(double degrees, boolean inCelsius) { // STUB! } // observer // -------- /* Returns this Temperature2's value as expressed on the Fahrenheit scale. */ public double degreesFahrenheit() { return 0.0; // STUB!! } // mutators // -------- /* Sets this Temperature2 object to the specified number of degrees on ** the Fahrenheit scale. */ public void setToFah(double fahDeg) { } // STUB! /* Changes this Temperature2 object by the specified number of Fahrenheit ** degrees. */ public void changeByFah(double fahDeg) { } // STUB! // private stuff // ------------- // The ratio describing the change in a temperature reading on the Celsius // scale vs. that on the Fahrenheit scale. (A change of five degree Celsius // corresponds to a change of nine degrees Celsius.) private static final double CEL_TO_FAH_RATIO = 5.0 / 9.0; /* Returns the equivalent change on the Celsius scale of a change by the ** specified # of degrees on the Fahrenheit scale. */ private double deltaFahToDeltaCel(double deltaFah) { return CEL_TO_FAH_RATIO * deltaFah; } /* Returns the equivalent, on the Celsius scale, of a temperature of the ** specified number of degrees on the Fahrenheit scale. */ private double fahToCel(double fahDeg) { return CEL_TO_FAH_RATIO * (fahDeg - 32); } }