Answer to Question #16373 in Java | JSP | JSF for Abdullah Almousawi

Question #16373
(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.
1
Expert's answer
2012-10-15T11:39:57-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS