98 927
Assignments Done
98.6%
Successfully Done
In April 2021

# Answer to Question #10014 in Java | JSP | JSF for convert

Question #10014
Write a program to convert temperature in Fahrenheit to temperature in Celsius
and vice versa according to the user&rsquo;s preference. The formula for the conversion in one
direction is as follows:
Tc = (5/9) * (Tf &ndash; 32)
Check the correctness and allowed scope of the entered data.
Let the user enter data from a file and write the conversion next to the initial value. For
example, if the user needs to convert F to C, create a file named FtoC.txt with random
Fahrenheit values. Read the file from your program and write next to each F value the C
conversion. Do this for CtoF as well.
1
2012-05-25T09:26:26-0400
import java.io.IOException;
public class Question10014 {
public static double fahrenheitToCelsius(double Tf){
return (5.0/9)*(Tf-32);
}
public static double celsiusToFahrenheit(double Tc){
return (9.0/5)*Tc +32;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
System.out.println(&quot;Please, enter Fahrenheit to convert it into Celsius&quot;);
System.out.println(&quot;In Celsius: &quot; + fahrenheitToCelsius(Tf));
System.out.println(&quot;Please, enter Celsius to convert it into Fahrenheit&quot;);
System.out.println(&quot;In Fahrenheit: &quot; + celsiusToFahrenheit(Tc));
} catch (NumberFormatException e) {
System.out.println(&quot;Wrong format!&quot;);
System.exit(1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!