Write a Temperature class that represents temperatures in degrees in Celsius, Fahrenheit and Kelvin. Use a floating-point number for the temperature and a character (type char) for the scale: 'C' for Celsius, 'F' for Fahrenheit and 'K' for Kelvin. The class should have
a) Four constructors: one for the degrees, one for the scale, one for both the degrees and scale, and a no-argument constructor. For each of these constructors, assume zero degrees if no value is specified and Celsius if no scale is given.
b) Three accessor methods: one to return the temperature in degrees Celsius, one to return the temperature in degrees Fahrenheit, one to return the temperature in degrees Kelvin.
For conversion between scales you can use the following formulas:
Celsius = 5/9 x (Fahrenheit - 32)
Kelvin = Celsius + 273.15
c) Three set methods: one to set the temperature, one to set the scale and one to set both.
d) Three comparison methods: one to test whether two temperatures are equal, one to test whether one temperature is greater than the other and one to test whether one temperature is less than the other.
e) a toString method: to display the temperature and scale. The output should look like 32° C (You can copy the degree sign from here to put in your code)
Write a test program to demonstrate your class. Be sure to use all of your methods in the test program.
Recently Asked Questions
- How can i put E2-6 into a chart form? Im trying to finish the homework but cant see the correlation between your answers and my chart.
- Define cost of capital and discusshow firms estimate their costs of capital.
- ______________is a term insurance policy that permits the policy owner to exchange the policy for cash value policy without having to demonstrate insurability .