15 marks Question 6.... The fictitious company Shiver Or Sweat develops temperature sensors for build- ings. They have t
Posted: Thu Jun 02, 2022 8:14 am
Question 6.... The fictitious company Shiver Or Sweat develops temperature sensors for build- ings. They have to develop a class that can be used for reading the temperature. You have just been hired by this company, and you are now to design part of this class, Sensor. A method read has already been written which returns a double indicating the temperature reading in Celsius. public double read() {...} If the connection to the physical sensor is out of order read returns -300 although this happens quite rarely. (a) Implement a method readTemperature which calls the read method. You 5 marks should throw an exception when the read method returns a value of -300. public double readTemperature () throws Exception { // YOUR CODE } (b) For this example, why is it preferable to throw an exception against return- 2 marks ing the value -300 which the calling method could check? (c) Write a method monitor which monitors the temperature. The method has 8 marks two arguments, low and high. public void monitor (double low, double high) { // YOUR CODE } The method monitor should read the temperature every second, and write out a warning (to System.err) if the temperature is below low or above high. If there is no response from the sensor for one minute (the sensor returns -300 every time it is queried within that minute), the monitor method should write out a special warning (to System.err). You may find the following method of assistance: public static void sleep (long mills) throws InterrupedException sleep is from the Thread class and it will pause execution for mills mil- liseconds.
15 marks