(Temperature Class) Create a class called Temperature that is used to convert temperatures from/to Celsius/Fahrenheit. Temperature should include one instance variable— temperature degree (type double). Your class should have a constructor that initializes instance variable. Provide set and get methods for it. In addition, provide the following two methods
toCelsius() that converts and returns the temperature degree in Celsius.
toFahrenheit()that converts and returns the temperature degree in Fahrenheit.
Write a test application named TemperatureTest that demonstrate the following sample output using Temperature class.
import java.util.Scanner;
public class Main {
/**
& *@param farenheit int& temperatur
*/
& public static double toCelsius(int farenheit) {
& double res=0.0;
& res=(farenheit-32)*5/9;
& return res;
& }
&
& /**
& *@param celsium int& temperatur
*/
& public static double toFahrenheit(int celsium) {
& double res=0.0;
& res=(celsium+32)*5/9;
& return res;
& }
/**
& * @param args
& */
public static void main(String[] args) {
& // TODO Auto-generated method stub
& int celsium=0,farenheit=0, conwertCelsium=0,conwertFarenheit=0;
& Scanner sc =new Scanner (System.in);
& System.out.println("Input temperatur in C ");
& celsium=sc.nextInt();
& System.out.println("Resoult& in F "+ toFahrenheit(celsium));
& System.out.println("Input temperatur in F ");
& farenheit=sc.nextInt();
& System.out.println("Resoult& in C "+ toCelsius(farenheit));
&
}
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
JavaJSPJSF