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'.
public class Test{public static void main(String []args){Conversion c = new Conversion(); //Creating object of the 'Conversion' classc.setc(37.0); //calling setter method 'setc' to set the value 37.0 in variable cdouble a= c.calculate(); //Calling 'Calculate' methodSystem.out.println(c.c+" degree celsius to fahrenheit is "+a); //Printing result}}
The output of this program seems like this:-
Comments
Post a Comment