Class TemperatureReading4
java.lang.Object
|
+----TemperatureReading4
- public class TemperatureReading4
- extends Object
This class encapsulates the data from a temperature reading.
The details of how a temperature is stored are hidden from the
user of objects created from this class. The public interface of
this class requires that the scale of a temperature must always
be specified. This provides a safe way to store temperature values.
-
BOILING_C
-
-
BOILING_F
-
-
CELCIUS
-
-
FAHRENHEIT
-
-
FREEZING_C
-
-
FREEZING_F
-
-
TemperatureReading4()
- The default constructor.
-
TemperatureReading4(double, char)
- A constructor that specifies the scale for the temperature.
-
convertCtoF(double)
- A static method that converts numbers from a Celsius value to a Fahrenheit value.
-
convertFtoC(double)
- A static method that converts numbers from a Fahrenheit value to a Celsius value.
-
getTemperatureC()
- Retrieve the temperature value using the Celsius scale.
-
getTemperatureF()
- Retrieve the temperature value using the Fahrenheit scale.
-
getTimeOfReading()
- Retrieve a reference to the Date object that holds the time of the temperature reading.
-
setTemperatureC(double)
- Set the temperature value using the Celsius scale.
-
setTemperatureF(double)
- Set the temperature value using the Fahrenheit scale.
-
setTimeOfReading(Date)
- Set the Date object that holds the time of the temperature reading.
-
toString()
-
BOILING_C
public static final double BOILING_C
BOILING_F
public static final double BOILING_F
FREEZING_C
public static final double FREEZING_C
FREEZING_F
public static final double FREEZING_F
CELCIUS
public static final char CELCIUS
FAHRENHEIT
public static final char FAHRENHEIT
TemperatureReading4
public TemperatureReading4()
- The default constructor.
TemperatureReading4
public TemperatureReading4(double temperature,
char scale)
- A constructor that specifies the scale for the temperature. Throws an IllegalArgumentException if an improper temperature scale is specified.
- Parameters:
- temperature - the temperature in either Celsius or Fahrenheit
- scale - specifies the scale for temperature, either FAHRENHEIT or CELCIUS
getTemperatureC
public double getTemperatureC()
- Retrieve the temperature value using the Celsius scale.
getTemperatureF
public double getTemperatureF()
- Retrieve the temperature value using the Fahrenheit scale.
getTimeOfReading
public Date getTimeOfReading()
- Retrieve a reference to the Date object that holds the time of the temperature reading.
setTemperatureC
public void setTemperatureC(double degreesC)
- Set the temperature value using the Celsius scale. Throws IllegalArgumentException if the temperature value given is not realistic.
- Parameters:
- degreesC - new temperature value in degreees Celsius
setTemperatureF
public void setTemperatureF(double degreesF)
- Set the temperature value using the Fahrenheit scale. Throws IllegalArgumentException if the temperature value given is not realistic.
- Parameters:
- degreesF - new temperature value in degreees Fahrenheit
setTimeOfReading
public void setTimeOfReading(Date newDate)
- Set the Date object that holds the time of the temperature reading.
- Parameters:
- newDate - a reference to a Date object
toString
public String toString()
- Overrides:
- toString in class Object
convertCtoF
public static double convertCtoF(double degreesC)
- A static method that converts numbers from a Celsius value to a Fahrenheit value.
- Parameters:
- degreesC - a number that is interpreted as a temperature in degrees Celsius
convertFtoC
public static double convertFtoC(double degreesF)
- A static method that converts numbers from a Fahrenheit value to a Celsius value.
- Parameters:
- degreesF - a number that is interpreted as a temperature in degrees Fahrenheit