Created
November 29, 2019 20:12
-
-
Save gitaficionado/32268d9093163e7092ffa87e6aa7838c to your computer and use it in GitHub Desktop.
Conversions between Celsius and Fahrenheit) Write a class that contains the fol-lowing two methods:/** Convert from Celsius to Fahrenheit */public static double celsiusToFahrenheit(double celsius)/** Convert from Fahrenheit to Celsius */public static double fahrenheitToCelsius(double fahrenheit)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
*(Conversions between Celsius and Fahrenheit) Write a class that contains | |
*the fol-lowing two methods:/** Convert from Celsius to Fahrenheit | |
*/public static double celsiusToFahrenheit(double celsius)/** | |
*Convert from Fahrenheit to Celsius | |
*/public static double fahrenheitToCelsius(double fahrenheit) | |
*The formula for the conversion is: | |
*fahrenheit = (9.0 / 5) | |
* celsius + 32celsius = (5.0 / 9) * (fahrenheit – 32) | |
*Write a test program that invokes these methods to display the following tables | |
*See page page 216 and 217 for more information. | |
*/ | |
public class ConversionsBTWCelsiusFahrenheit_06_08 { | |
public static void main(String[] args) { | |
System.out.printf("%-15s%-15s%5s%-15s%-15s\n", "Celsius", "Fahrenheit", "| ", "Fahrenheit", "Celsius"); | |
System.out.println("----------------------------------------------------------"); | |
double celsius = 40; double farenheit = 120; | |
for (int i = 1; i <= 10; celsius--, farenheit -= 10, i++) { | |
System.out.printf("%-15.1f%-15.1f%5s%-15.1f%-15.2f\n", celsius, celsiusToFahrenheit(celsius), "| ", farenheit, | |
fahrenheitToCelsius(farenheit)); | |
} | |
} | |
public static double celsiusToFahrenheit(double celsius) { | |
___________________ (9.0 / 5.0) * ________ + 32; | |
} | |
public static double fahrenheitToCelsius(double fahrenheit) { | |
______________ (5.0 / 9) * (____________ - 32); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment