Ask Question

Assume that two classes 'Temperature' and 'Sensor' have been defined. 'Temperature' has a constructor that accepts a double parameter. 'Sensor' has a method named 'getReading' which returns the sensor's current reading (a double). Write a static method 'create' (that could be added to the 'Temperature' class) that accepts a 'Sensor' object. 'create' gets the value of the current reading of the 'Sensor' object, and returns a new 'Temperature' object that is based on this reading.

+2
Answers (1)
  1. 17 May, 06:56
    0
    The answer for the following question is given as:

    public static Temperature create (Sensor ob)

    {

    return new Temperature (ob. getReading ());

    }

    Explanation:

    In this we have create a static method of Temperature class which accept a 'Sensor' object and return the new 'Temperature' object that calls the 'getReading () ' function This function returns the sensor's current reading.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Assume that two classes 'Temperature' and 'Sensor' have been defined. 'Temperature' has a constructor that accepts a double parameter. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers