For My Programming Lab - Java: Write a Temperature class that will hold a temperature in Fahrenheit...

50.1K

Verified Solution

Question

Programming

For My Programming Lab - Java:

Write a Temperature class that will hold a temperature inFahrenheit and provide methods to get the temperature inFahrenheit, 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 set Fahrenheit method accepts a Fahrenheittemperature (as a double ) and stores it in the ftemp field.
• getFahrenheit: Returns the value of the ftemp field as aFahrenheit temperature (no conversion required)
• getCelsius: Returns the value of the ftemp field converted toCelsius. Use the following formula to convert to Celsius:
Celsius = (5/9) * (Fahrenheit - 32)
• getKelvin: Returns the value of the ftemp field converted toKelvin. Use the following formula to convert to Kelvin:
Kelvin = ((5/9) * (Fahrenheit - 32)) + 273

Demonstrate the Temperature class by writing a separate programthat asks the user for a
Fahrenheit temperature. The program should create an instance ofthe Temperature class ,
with the value entered by the user passed to the constructor . Theprogram should then
call the object 's methods to display the temperature in thefollowing format (for example,
if the temperature in Fahrenheit was -40):

The temperature in Fahrenheit is -40.0
The temperature in Celsius is -40.0
The temperature in Kelvin is 233.0

Answer & Explanation Solved by verified expert
4.3 Ratings (913 Votes)
import javautil class Temperature private double ftemp public Temperaturedouble ftemp constructor thisftemp ftemp public void setFahrenheitdouble ftemp set Fahrenheit Temperature thisftemp ftemp public double    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students