Thermometer
Part 1: Design and realize a Java class
Thermometer
to represent thermometers. The following
functionalities are of interest for thermometers:
temperature t | type |
---|---|
45 < t | "very hot" |
35 < t <= 45 | "hot" |
18 < t <= 35 | "medium" |
0 < t <= 18 | "cold" |
t <= 0 | "very cold" |
To convert degrees Celsius in degrees Fahrenheit, use the following conversion formula: f = c * 9/5 + 32.
Part 2:
Write a client that uses the class Thermometer
as follows.
"very hot"
, "hot"
, etc.).
To print out the information, make use of an auxiliary method.
"The temperature did not change."
,
otherwise it prints "Attention, the temperature has
changed."
.
Part 3: Write a static method outside the class
Thermometer
that, given a thermometer, repeatedly reads from the
keyboard the temperature in Celsius passing it to the thermometer as
measurement. The method should stop reading from keyboard when
JOptionPane.showInputDialog
returns null
, i.e., the
user has pressed the Cancel
button. At this point the method
returns the maximum temperature, in Fahrenheit, among those read.
Part 4: Write a static method outside the class
Thermometer
that, given a thermometer, repeatedly reads from the
keyboard the temperature in Celsius passing it to the thermometer as
measurement, and at the end returns the average temperature in Fahrenheit.
Again, the method should stop reading from keyboard when
JOptionPane.showInputDialog
returns null
.