Ask Question
19 September, 00:29

Write a Temperature class that will hold a temperature in Fahrenheit, and will provide methods to get and display the temperature in Fahrenheit, Celsius, and Kelvin. The Temperature class should have the following instance variable: ftemp - A double that holds a Fahrenheit temperature. The Temperature class should have the following methods: ReadInput - Uses a Scanner method to populate ftemp with double value. getFahrenheit - Returns the value of the ftemp field, as a Fahrenheit temperature. getCelsius - Returns the value of the ftemp field converted to Celsius. getKelvin - Returns the value of the ftemp field converted to Kelvin. DisplayOutput - The Fahrenheit temperature and the equivalent values in Celsius and Kelvin are gotten and displayed, one per line, and each along with an appropriate message.

+1
Answers (1)
  1. 19 September, 03:37
    0
    See explaination

    Explanation:

    import java. util. Scanner;

    public class TemperatureTest {

    public static void main (String[] args) {

    Scanner sc = new Scanner (System. in);

    System. out. print ("Enter Fahrenheit temperature: ");

    double ftemp = sc. nextDouble ();

    Temperature temp = new Temperature (ftemp);

    System. out. println ("The temperature in Fahrenheit is " + temp. getFahrenheit ());

    System. out. println ("The temperature in Celsius is " + temp. getCelsius ());

    System. out. println ("The temperature in Kelvin is " + temp. getKelvin ());

    }

    }

    class Temperature {

    double ftemp;

    Temperature (double ftemp) {

    this. ftemp = ftemp;

    }

    double getFahrenheit () {

    return ftemp;

    }

    double getCelsius () {

    return ((double) 5/9 * (ftemp-32));

    }

    double getKelvin () {

    return (((double) 5/9 * (ftemp-32)) + 273);

    }

    }

    Output:

    $ java TemperatureTest

    Enter Fahrenheit temperature: - 40

    The temperature in Fahrenheit is - 40.0

    The temperature in Celsius is - 40.0

    The temperature in Kelvin is 233.0
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a Temperature class that will hold a temperature in Fahrenheit, and will provide methods to get and display the temperature in ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers