Question: Implement a class Temp (that is a subclass of the object class) which represents a temperature reading and supports the following methods: __init__ () which

Implement a class Temp (that is a subclass of the object class) which represents a temperature reading and supports the following methods:

  1. __init__() which takes a numeric value and a single character string that represent a temperature measurement and scale and use the values to set the measurement and scale of the temperature stored in the object. If a temperature reading is not provided the default is 0.0 and if a scale is not provided the default is 'f' for Fahrenheit.

  2. setTemp() which enters a temperature and a scale from the user. The method first prompts the user for a scale ('c' for Celsius or 'f' for Fahrenheit), re-prompting if the user does not enter a valid character. Both uppercase and lowercase characters (e.g. 'c', 'C', 'f', or 'F') should work. Once a valid character representing a scale has been entered, the method updates the scale stored in the object. Once that is completed, the method goes on to prompt the user to enter a measurement. If the user enters something that cannot be evaluated as a numeric value (e.g. an int or float), the function repeatedly re-prompts the user. Once a valid numeric value has been entered, the function updates the temperature measurement stored in the object using the value. See below for example runs of the function.

  3. getC() which takes no parameters and returns the temperature measurement on the Celsius scale. If the temperature is already stored in Celsius, it just returns the measurement. Otherwise it computes the equivalent temperature in Celsius (without changing any values stored in the object) and returns it. Note that to convert a temperature Tf in Fahrenheit to one in Celsius you write: (Tf - 32) / 1.8.

  4. getF() which takes no parameters and returns the temperature measurement on the Fahrenheit scale. If the temperature is already stored in Fahrenheit , it just returns the measurement. Otherwise it computes the equivalent temperature in Fahrenheit (without changing any values stored in the object) and returns it. Note that to convert a temperature Tc in Celsius to one in Fahrenheit you write: Tc * 1.8 + 32.

The following shows how the Temp class and its methods could be used. Note that measure is the name I used for the temperature reading and scale for the scale of the reading as stored inside the object. You don't have to use those names, but you do have to make sure that getF() and getC() don't change their values:

Python 3.7.2 Shell File Edit She Debug Options Window Help >>> t1 - Temp () >>> t1.getc () >>> val t1.getF () >>val >>> t1.setTemp() Enter a scale (c for Celsius, f for Fahrenheit) $ is not a valid scale. Enter a scale (c for Celsius, f for Fahrenheit): G G is not a valid scale Enter a scale (c for Celsius, f for Fahrenhe it) : c Enter a temperature reading: five Please enter the reading using digits. Enter a temperature reading: ten Please enter the reading using digits. Enter a temperature reading: 5.5 >>> t1.getc () >>> t1.getF() 41.9 >> t1.measure >>> t1.scale >>> t1.getF() 41.9 >> t1.measure >>> t1.scale >>> t2 = Temp (50.5) >>> t2.getc () >>> t2 .getF() 50.5 >>> t3 - Temp (scale - 'C') >>> t3.getc () >>> t3 .getF() 32.0 Ln: 89 Col: 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!