Write a program, reading the temperature data from an input file, translating them to another temperature scale by the choice of user (F2C, C2F, K2C, C2K, K2F, F2K) and writing the calculated temperature values in output file. it is input file and output file java code . i am giving you the code you need to implement the code with I/O file import java.util.Scanner; public class Lab15{ public static void main(String[] args) { Scanner Keyboard = new Scanner(System.in); double Frahenhite, Celsius, Kelvin ; int input = 1; while (input==1) { for (int i = 1; i<=2; i++) { System.out.println("Choose an option"); System.out.println("FTC - Fahrenheit to Celsius"); System.out.println("CTF - Celsius to Fahrenheit"); System.out.println("FTK - Fahrenheit to Kelvin"); System.out.println("KTF - Kelvin to Fahrenheit"); System.out.println("CTK - Celsius to Kelvin"); System.out.println("KTC - Kelvin to Celsius"); System.out.println("\nEnter Choice: "); String Type= Keyboard.nextLine(); if (Type.equalsIgnoreCase("FTC")) { System.out.println("Enter the value of temperature in Fahrenheit degrees: "); Frahenhite = Keyboard.nextDouble(); Celsius= ((5*(Frahenhite-32))/9) ; System.out.println("The value of the temperature in Celsius = " + Celsius); } else if (Type.equalsIgnoreCase("CTF")) { System.out.println("Enter the value of temperature in Celsius degrees: "); Celsius = Keyboard.nextDouble(); Frahenhite = ((9*Celsius)/5)+32; System.out.println("The value of the temperature in Farhenhite = " + Frahenhite); } else if(Type.equalsIgnoreCase("CTK")) { System.out.println("Enter the value of temperature in Celsius degrees: "); Celsius = Keyboard.nextDouble(); Kelvin = Celsius +273 ; System.out.println("The value of the temperature in Kelvin = " + Kelvin); } else if(Type.equalsIgnoreCase("KTC")) { System.out.println("Enter the value of temperature in Kelvin degrees: "); Kelvin = Keyboard.nextDouble(); Celsius = Kelvin - 273 ; System.out.println("The value of the temperature in Celsius = " + Celsius); } else if(Type.equalsIgnoreCase("FTK")) { System.out.println("Enter the value of temperature in Frahenhite degrees: "); Frahenhite = Keyboard.nextDouble(); Kelvin =(5.0/9)*(Frahenhite - 32) + 273;; System.out.println("The value of the temperature in Kelvin = " + Kelvin); } else if(Type.equalsIgnoreCase("KTF")) { System.out.println("Enter the value of temperature in Kelvin degrees: "); Kelvin = Keyboard.nextDouble(); Frahenhite =(9.0/5)*( Kelvin - 273) + 32; System.out.println("The value of the temperature in Frahenhite = " + Frahenhite); } } System.out.println("End of series "); System.out.println("If you want to convert again enter 1 or enter any other number to exit the code "); input = Keyboard.nextInt(); }}}
Write a program, reading the temperature data from an input file, translating them to another temperature scale by the choice of user (F2C, C2F, K2C, C2K, K2F, F2K) and writing the calculated temperature values in output file.
it is input file and output file java code . i am giving you the code you need to implement the code with I/O file
import java.util.Scanner;
public class Lab15{
public static void main(String[] args) {
Scanner Keyboard = new Scanner(System.in);
double Frahenhite, Celsius, Kelvin ;
int input = 1;
while (input==1)
{
for (int i = 1; i<=2; i++) {
System.out.println("Choose an option");
System.out.println("FTC - Fahrenheit to Celsius");
System.out.println("CTF - Celsius to Fahrenheit");
System.out.println("FTK - Fahrenheit to Kelvin");
System.out.println("KTF - Kelvin to Fahrenheit");
System.out.println("CTK - Celsius to Kelvin");
System.out.println("KTC - Kelvin to Celsius");
System.out.println("\nEnter Choice: ");
String Type= Keyboard.nextLine();
if (Type.equalsIgnoreCase("FTC"))
{
System.out.println("Enter the value of temperature in Fahrenheit degrees: ");
Frahenhite = Keyboard.nextDouble();
Celsius= ((5*(Frahenhite-32))/9) ;
System.out.println("The value of the temperature in Celsius = " + Celsius);
}
else if (Type.equalsIgnoreCase("CTF"))
{
System.out.println("Enter the value of temperature in Celsius degrees: ");
Celsius = Keyboard.nextDouble();
Frahenhite = ((9*Celsius)/5)+32;
System.out.println("The value of the temperature in Farhenhite = " + Frahenhite);
}
else if(Type.equalsIgnoreCase("CTK"))
{
System.out.println("Enter the value of temperature in Celsius degrees: ");
Celsius = Keyboard.nextDouble();
Kelvin = Celsius +273 ;
System.out.println("The value of the temperature in Kelvin = " + Kelvin);
}
else if(Type.equalsIgnoreCase("KTC"))
{
System.out.println("Enter the value of temperature in Kelvin degrees: ");
Kelvin = Keyboard.nextDouble();
Celsius = Kelvin - 273 ;
System.out.println("The value of the temperature in Celsius = " + Celsius);
}
else if(Type.equalsIgnoreCase("FTK"))
{
System.out.println("Enter the value of temperature in Frahenhite degrees: ");
Frahenhite = Keyboard.nextDouble();
Kelvin =(5.0/9)*(Frahenhite - 32) + 273;;
System.out.println("The value of the temperature in Kelvin = " + Kelvin);
}
else if(Type.equalsIgnoreCase("KTF"))
{
System.out.println("Enter the value of temperature in Kelvin degrees: ");
Kelvin = Keyboard.nextDouble();
Frahenhite =(9.0/5)*( Kelvin - 273) + 32;
System.out.println("The value of the temperature in Frahenhite = " + Frahenhite);
}
}
System.out.println("End of series ");
System.out.println("If you want to convert again enter 1 or enter any other number to exit the code ");
input = Keyboard.nextInt();
}}}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images