Computer Applications
Write a class that contains the following two methods:
- public static double celsiusToFahrenheit(double celsius)
- public static double fahrenheitToCelsius(double fahrenheit)
Use the following formulas for temperature conversion:
- fahrenheit = (9.0 / 5) * celsius + 32
- celsius = (5.0 / 9) * (fahrenheit - 32)
Finally, invoke these methods in BlueJ to convert some test values.
Java
User Defined Methods
49 Likes
Answer
public class KboatTemperature
{
public static double celsiusToFahrenheit(double celsius) {
double f = (9.0 / 5) * celsius + 32;
return f;
}
public static double fahrenheitToCelsius(double fahrenheit) {
double c = (5.0 / 9) * (fahrenheit - 32);
return c;
}
public static void main(String args[]) {
double r = celsiusToFahrenheit(100.5);
System.out.println("100.5 degree celsius in fahrenheit = " + r);
r = fahrenheitToCelsius(98.6);
System.out.println("98.6 degree fahrenheit in celsius = " + r);
}
}Output

Answered By
25 Likes