Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gitaficionado/a9b2344c2b7d1e3bfedd06369ce4ae18 to your computer and use it in GitHub Desktop.
Save gitaficionado/a9b2344c2b7d1e3bfedd06369ce4ae18 to your computer and use it in GitHub Desktop.
(Conversions between feet and meters) Write a class that contains the following two methods:/** Convert from feet to meters */public static double footToMeter(double foot)/** Convert from meters to feet */public static double meterToFoot(double meter) See page 217 in the Liang text for more informaiton.
/**
*(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 + 32
*celsius = (5.0 / 9) * (fahrenheit – 32)
*/
public class ConversionsBtwFeetMetersExercise_06_09 {
public static void main(String[] args) {
System.out.printf("%4s%10s%20s%10s\n", "Feet", "Meters", "Meters", "Feet");
System.out.println("---------------------------------------------");
double foot = 1; double meter = 20;
for (int i = 1; i <= 10; foot++, meter += 5, i++) {
System.out.printf("%4.1f%10.3f%20.1f%10.3f\n", foot, footToMeter(foot), meter, meterToFoot(meter));
}
}
/** Converts from feet to meters */
public static double footToMeter(double _______) {
_________________ 0.305 * _______;
}
/** Converts from meters to feet */
public static double meterToFoot(double _______) {
_____________ (1 / 0.305) * ______________;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment