15 marks Question 6.... The fictitious company Shiver Or Sweat develops temperature sensors for build- ings. They have t

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

15 marks Question 6.... The fictitious company Shiver Or Sweat develops temperature sensors for build- ings. They have t

Post by answerhappygod »

15 Marks Question 6 The Fictitious Company Shiver Or Sweat Develops Temperature Sensors For Build Ings They Have T 1
15 Marks Question 6 The Fictitious Company Shiver Or Sweat Develops Temperature Sensors For Build Ings They Have T 1 (122.33 KiB) Viewed 9 times
15 marks 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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply