Computer Science, asked by jasmineabraham3121, 5 months ago

write a explanation for temperature class that will hold a temperature in fahrenheit and provide methods to get temperature in fahrenheit, celsius and kelvin in java​

Answers

Answered by CoderRishav
1

Answer:

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);

}

}

Hope you like this answer, so please mark as brainlist and MY SUGGESTION IS THAT TO ANALYZE THIS CODE FOR KNOW HOW IT WORKS BECAUSE I ALSO DO THIS FORMAT TO PRACTICE AND ALSO SEE SOME JAVA PROJECTS ON GITHUB AND ANALYZE THAT, TO BE A GOOD JAVA DEVELOPER.

Similar questions