1. (Conversions between Celsius and Fahrenheit) Write a class
that contains the following method:
/** Converts from Celsius to Fahrenheit */
public static double celsiusToFahrenheit(double celsius)
The formula for the conversion is:
fahrenheit = (9.0 / 5) * celsius + 32
Write a test program that invokes these methods to display the following tables:
Celsius Fahrenheit
40.0 105.0
2. (Conversions between feet and meters) Write a class that
contains the following method:
/** Converts from feet to meters */
public static double footToMeter(double foot)
The formula for the conversion is:
meter = 0.305 * foot
Write a test program that invokes these methods to display the following tables:
Feet Meters
1.0 0.305
SOLUTION (for question 1)
/**
* @(#)labChap5_Methods.java
*
* labChap5_Methods application
*
* @author
* @version 1.00 2010/8/25
*/
import javax.swing.*;
public class labChap5_Methods {
public static void main(String[] args) {
String AnsString = JOptionPane.showInputDialog ("Please Enter Celsius");
double cel =Double.parseDouble(AnsString);
double feh =celsiusToFahrenheit(cel);
System.out.println("Celcius Fahrenheit" );
System.out.println("---------------------------------");
System.out.println(cel +" " + feh);
}
public static double celsiusToFahrenheit(double celsius)
{
return ((9.0 / 5) * celsius + 32);
}
}
No comments:
Post a Comment