Write a program to convert temperature in Fahrenheit to temperature in Celsius
and vice versa according to the user’s preference. The formula for the conversion in one
direction is as follows:
Tc = (5/9) * (Tf – 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
Expert's answer
2012-05-25T09:26:26-0400
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; 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 BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { System.out.println("Please, enter Fahrenheit to convert it into Celsius"); double Tf = Double.parseDouble(br.readLine()); System.out.println("In Celsius: " + fahrenheitToCelsius(Tf)); System.out.println("Please, enter Celsius to convert it into Fahrenheit"); double Tc = Double.parseDouble(br.readLine()); System.out.println("In Fahrenheit: " + celsiusToFahrenheit(Tc)); } catch (NumberFormatException e) { System.out.println("Wrong format!"); System.exit(1); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment