/* FC.java - convert between Fahrenheit and Celcius. * First, give the user a choice. Which way do you want to go? * Then, we handle the 2 scenarios. Ask the user for a temperature, * and then convert it to the other scale. * Note that we need to use a scanner in both cases, so let's open * the scanner at the beginning of the program. */ import java.util.Scanner; public class FC { public static void main(String [] args) { Scanner sc = new Scanner(System.in); System.out.printf("Temperature conversion program.\nMENU...\n"); System.out.printf("(1) Fahrenheit to Celcius\n"); System.out.printf("(2) Celcius to Fahrenheit\n"); System.out.printf("Please enter the number of your choice: "); int choice = sc.nextInt(); // Do the appropriate conversion. // When you multiply, don't forget the * sign! // Also note that variables that we declare are only alive in // the block in which they are declared. if (choice == 1) { System.out.printf("Enter Fahrenheit temperature: "); double fahrenheit = sc.nextDouble(); double celcius = 5.0/9.0 * (fahrenheit - 32.0); System.out.printf("Equivalent Celcius is %.1f\n", celcius); } else { System.out.printf("Enter Celcius temperature: "); double celcius = sc.nextDouble(); double fahrenheit = 9.0/5.0 * celcius + 32.0; System.out.printf("Equivalent Fahrenheit is %.1f\n", fahrenheit); } } }