Temperature Convert

NOW IN THIS PART U WILL LEARN HOW TO CONVERT TEMPERATURE TO FAHRENHEIT OR VICE VERSA
[sourcecode=’java’]
public class Temperature {

public static double temp;
public static final double FAHRENHIET_FREEZ = 32.0;
public static final double FAHRENHIET_BOIL = 220.0;
public static final double CELCIUS_FREEZ = 0.0;
public static final double CELCIUS_BOIL = 100.0;

//client code
//now here you can input the value either of fahrenheit
//or celcius only (but only one);
public static double celcius;
public static double fahrenheit;

public static double fahrenheitToCel(){

return (fahrenheit-FAHRENHIET_FREEZ)*(5.0/9.0);
}

public static double celToFahrenheit(){

return celcius*(9.0/5.0) + FAHRENHIET_FREEZ;

}
public void display(){

if(this.fahrenheit > FAHRENHIET_FREEZ){
System.out.println(“The temperature is “+
this.fahrenheit +” Fahrenheit which is equal to ”
+ Temperature.fahrenheitToCel() +” celcius “);
}
else{
System.out.println(“The temperature is “+this.celcius
+” Celcius which is equal to ” +
Temperature.celToFahrenheit() +” Fahrenheit ” );
}

}

public static void main (String[] args) {

Temperature temp = new Temperature();
temp.display();

}

}
[/sourcecode]

2 thoughts on “Temperature Convert”

  1. Do get it right thanks, it is ‘Fahrenheit’ and ‘Celsius’.

    And why have you defined a manifest constant for Fahrenheit freezing point and still used 32.0 in the code?

Leave a Reply