The fomula? celsius = 5.0 / 9.0 * ( fahrenheit - 32 ); fahrenheit = 9.0 / 5.0 *
ID: 3559410 • Letter: T
Question
The fomula?
celsius = 5.0 / 9.0 * ( fahrenheit - 32 );
fahrenheit = 9.0 / 5.0 * celsius + 32;
Create a TemperatureConverter program with static methods toCelsius and toFahrenheit. See Exercise 22 on page 239 for the formulas. Each method has a double parameter and returns a double. Each method converts and returns the converted temperature. Input and output must be done in main. The program will prompt for a Celsius temperature, then will call the toFahrenheit method and will display the converted temperature with 1 place past the decimal point. The program will then prompt for a Fahrenheit temperature, will call the toCelsius method and will display the converted temperature with 1 place past the decimal point.Explanation / Answer
import java.util.Scanner;
class TemperatureConverter
{
public static double toCelcius(double t)
{
return (Math.round(((5.0 / 9.0 * ( t - 32 )) * 10)) / 10.0);
}
public static double toFarenheit(double t)
{
return (Math.round(((9.0 / 5.0 * t + 32) * 10) / 10.0));
}
public static void main (String args[])
{
Scanner input = new Scanner (System.in);
double temp;
System.out.println( "Enter temperature in Celcius");
temp = input.nextDouble();
System.out.println( "Temperature in Celcius " + temp+ " is " + toFarenheit(temp) + " in Farenheit");
System.out.println( "Enter temperature in Farenheit");
temp = input.nextDouble();
System.out.println( "Temperature in Farenheit " + temp+ " is " + toFarenheit(temp) + " in Celcius");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.