Problem

Temperature ClassWrite a Temperature class that will hold a temperature in Fahrenheit and...

Temperature Class

Write a Temperature class that will hold a temperature in Fahrenheit and provide methods to get the temperature in Fahrenheit, Celsius, and Kelvin. The class should have the following field:

ftemp —A double that holds a Fahrenheit temperature.

The class should have the following methods:

Constructor—The constructor accepts a Fahrenheit temperature (as a double ) and stores it in the ftemp field.

setFahrenheit —The setFahrenheit method accepts a Fahrenheit temperature (as a double ) and stores it in the ftemp field.

getFahrenheit —Returns the value of the ftemp field, as a Fahrenheit temperature (no conversion required).

getCelsius —Returns the value of the ftemp field converted to Celsius.

getKelvin —Returns the value of the ftemp field converted to Kelvin.

Use the following formula to convert the Fahrenheit temperature to Celsius:

Celsius = (5/9) × (Fahrenheit – 32)

Use the following formula to convert the Fahrenheit temperature to Kelvin:

Kelvin = ((5/9) × (Fahrenheit – 32)) + 273

Demonstrate the Temperature class by writing a separate program that asks the user for a Fahrenheit temperature. The program should create an instance of the Temperature class, with the value entered by the user passed to the constructor. The program should then call the object’s methods to display the temperature in Celsius and Kelvin.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT