Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

temperature conversion from Far to Celcius

Status
Not open for further replies.

mutual

Programmer
Jun 8, 2000
6
US
I'm trying to write a program that converts temperature from Far to cel and opposite.It shoul have two functions<br>FtoC and CtoF.they should be declared as private and accept sinfle argument of type int,return a value of type int.<br>I should pass fahrenheit constant as an arg to FtToC function and pass Celsius constant to CtoF function.<br><br>i even don't know how to start.Please help I'm very new in java
 
Dear mutual,<br><br>If you provide the math caculations here in a post I can help with the java code.<br><br>-pete
 
Does the program have to be GUI or is it text based?<br><br>I don't remember the formulae offhand but they are rather simply and of the form y = f(x), meaning that for one x value there is one y value. If you can manage to type out the formulae to display in this forum, then you should be able to convert it to java.<br><br>a simple outline:<br><br>public class Conversion<br>{<br>&nbsp;private double input; // the temperature to be converted<br>&nbsp;private double output;// the value of the converted temperature<br>&nbsp;Char boolean fOrC; //used to determine which way to convert, from F to C or C to f. It Should only contain an &quot;f&quot; or &quot;c&quot;<br>&nbsp;public static void main(String args[]) <br>{<br>&nbsp;//get the input from the user and assign it to the appropriate variables<br><br>if(fOrC == 'c')<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;output = cToF(input);<br>&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;output = fToC(input);<br>&nbsp;<br>&nbsp;System.out.println(output);<br><br>}<br><br>&nbsp;<br>//the methods<br>public double cToF(double input){}<br><br>public double fToC(double input){}<br><br><br>}<br><br>All you have to do is fill in the methods and it should work. I will not complete the code for you because this sounds suspiciously like a homework question, but there should be enough to get you started. <p> fenris<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br> I am interested in Mining Software, as well as Genetic Algorithms.
 
Thank you all, I figire out how to do it.It works. The only thing I didn't get that assigment was to code two variables type integer in main function and other 2 functions CtoF and FtoC should be declared as static and private.when I declare 2 variables in main compiler wouldn't recognize it.So I declared it on class level and it works fine.But that not exactly what i supposed to do.Any suggestions ??&nbsp;&nbsp;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top