In: Computer Science
(java))Write a “Temperature Conversion” program.
Declare choice, tempIn, tempOut variables
Prompt the user with the messages to choose: 1) Centigrade to Fahrenheit, 2) Fahrenheit to centigrade.
Prompt the user for temperature value (tempIn) to convert.
Calculate new tempOut. The calculation of the new tempOUT depends on choice 1 or 2 above.\
( Lookup up the C to F formula online, loop up the F to C formula online )
Print out the the F and the C temps.
Be sure to use the C and F temperature notation ASCII symbol.
If you have any doubts, please give me comment...
import java.util.Scanner;
public class TemperatureConversion {
public static void main(String[] args) {
int choice;
double tempIn, tempOut;
Scanner scnr = new Scanner(System.in);
System.out.println("MENU");
System.out.println("1) Centigrade to Fahrenheit");
System.out.println("2) Fahrenheit to centigrade.");
System.out.print("Enter your choice: ");
choice = scnr.nextInt();
if (chocie == 1 || choice == 2) {
System.out.print("Enter temperature value: ");
tempIn = scnr.nextDouble();
if (choice == 1) {
tempOut = (tempIn * 9 / 5.0) + 32;
System.out.println("C = " + tempIn + "\u00B0, F = " + tempOut + "\u00B0");
} else {
tempOut = (tempIn - 32) * 5 / 9.0;
System.out.println("C = " + tempIn + "\u00B0, F = " + tempOut + "\u00B0");
}
} else {
System.out.println("Invalid choice\n");
}
}
}