Convert Celsius to Fahrenheit

Convert temperature in degree Celsius to Fahrenheit

Different methods are defined to convert temperature into Fahrenheit. you can define the sub-methods and the main method in the same class or the two different two classes, and here we did the same. The calculation method 'Calculate' and the setter method 'setc' is defined in a class called 'Conversion' and the main method is defined in another class named 'Test'.
Getter methods are used to set the value in variables. The data gets set here when the values are passed as an argument form another method that might be the simple method or the main method.
The syntax for the setter method is,


public void [methodName](Parameter)
{
Statement(s);
}


Here is the program is written inside the class 'Calculate'.


And the main function written inside the Test class is.



public class Test
{
    public static void main(String []args)
    {
        Conversion c = new Conversion(); //Creating object of the 'Conversion' class
        c.setc(37.0); //calling setter method 'setc' to set the value 37.0 in variable c
        double a= c.calculate(); //Calling 'Calculate' method
        System.out.println(c.c+" degree celsius to fahrenheit is "+a); //Printing result
    }
}


The output of this program seems like this:-


Comments

Popular posts from this blog

Java Program to make a comparison between numbers

Java program using Scanner Class

Java program to print 'Hello World'