Question: Write a class that contains the following three methods ( 1 8 Points ) : / * * Convert from Celsius to Fahrenheit * /

Write a class that contains the following three methods (18 Points):
/** Convert from Celsius to Fahrenheit */
public static double celsiusToFahrenheit(double celsius)
/** Convert from Fahrenheit to Celsius */
public static double fahrenheit ToCelsius(double fahrenheit)
/** Print conversion result */ public void printConversion(String conversionType, double value)
The formulas for the conversions are:
Fahrenheit =(9/5)* Celsius +32
Celsius =(5/9)*(Fahrenheit -32)
Instructions:
The printConversion method should take a string ("celsius ToFahrenheit" or "fahrenheitToCelsius") to specify the type of conversion and a value for conversion, then print the result.
For example:
If the input is "celsius ToFahrenheit" and value =25, it should print 25.0 degrees Celsius is 77.0 degrees Fahrenheit.
If the input is "fahrenheit ToCelsius" and value =77, it should print 77.0 degrees Fahrenheit is 25.0 degrees Celsius.
If the input is neither "celsius ToFahrenheit" nor "fahrenheit ToCelsius", it should print Imalid conversion type. Please use
celsius ToFahreheit' or yahrenheitToCelsius
Write a main method to test your code by performing the following tasks (you don't need to take inputs from the user): (10 Points)
Convert 25 degrees Celsius to Fahrenheit and print the result.
Convert 77 degrees Fahrenheit to Celsius and print the result.
Test with an invalid conversion type and print the appropriate message.
Expected output:
25.0 degrees Celsius is 77.0 degrees Fahrenheit.
77.0 degrees Fahrenheit is 25.0 degrees Celsius.
Invalid conversion type. Please use 'celsius ToFahrenheit' or 'fahrenheit ToCelsius'

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!