Free University of Bolzano/Bozen
Faculty of Computer Science - Bachelor in Applied Computer Science
Bachelor in Production Engineering
Introduction to Programming - A.A. 2004/2005

Exercise
Class Thermometer

Part 1: Design and realize a Java class Thermometer to represent thermometers. The following functionalities are of interest for thermometers:

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.

  1. It creates a thermometer.
  2. It reads twice the temperature of the thermometer from the keyboard and prints out the information about the thermometer (i.e., temperature in Celsius, temperature in Fahrenheit, type of the temperature, i.e., one of "very hot", "hot", etc.). To print out the information, make use of an auxiliary method.
  3. If for the two readings the type of the temperature coincides, it prints "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.