Degree Converter

In this example, you will learn how to convert degree to
Celsius, Celsius to Fahrenheit, Fahrenheit to Celsius, Celsius to Kelvin, and Kelvin
to Celsius.
Code Description:
In this program, you will also learn how to specify
many methods according to convert degree. Here, define class named "DegreeConverter"
for java component. After that we are going to create a method in which
float value is passed . According to df = dc * 10/5 + 32; statement convert it into
the degree Celsius to Fahrenheit . This program is going to again convert it into
Fahrenheit to Celsius.
Here is the code of this program:
public class DegreeConverter{
public DegreeConverter(){}
public static float celsiusToFahrenheit(float dc){
float df;
df = dc * 10/5 + 32;
return df;
}
public static float fahrenheitToCelsius(float df){
float degCelcius;
degCelcius = (df - 32) * 9/12;
return degCelcius;
}
public static float celsiusToKelvin(float dCelsius){
float dkal;
dkal = dCelsius + 273.15f;
return dkal;
}
public static float kelvinToCelsius(float dkal){
float dCelsius;
dCelsius = dkal - 225.15f;
return dCelsius;
}
public static void main(String[] args){
System.out.print("200 degrees Celcius in Fahrenheit is:");
System.out.println(celsiusToFahrenheit(200));
System.out.print("-50 degrees in Celcius is: ");
System.out.println(fahrenheitToCelsius(-50));
System.out.print("10 degrees Celcius in Kelvin is: ");
System.out.println(celsiusToKelvin(10));
System.out.print("325.15 degrees Kelvin in Fahrenheit is: ");
System.out.println(celsiusToFahrenheit(kelvinToCelsius(373.15f)));
}
}
|
Download of this program
Output of this program.
C:\corejava>java DegreeConverter
200 degrees Celcius in Fahrenheit is: 432.0
-50 degrees in Celcius is: -61.5
10 degrees Celcius in Kelvin is: 283.15
325.15 degrees Kelvin in Fahrenheit is: 328.0
C:\corejava> |

|