In: Computer Science
Problem specifications:
You are tasked with developing a complete temperature conversion program in Java.
Your program should:
-prompt the user with the following menu:
-1-Convert Fahrenheit to Celcius
-2-Convert Celcius to Fahrenheit
-3-Quit Program
The menu must be coded in its own method.
-If user select option 1 then call a method that prompts the user to enter a value in degrees Fahrenheit and return it back to main.
-call a method that converts from Fahrenheit to Celcius
-call a method that displays the degrees in Fahrenheit and its equivalent in degress celcius.
-If user select option 2 then call a method that prompts the user to enter a value in degrees Celcius and return it back to main.
-call a method that converts from Celcius to Fahrenheit.
-call a method that displays the degrees in Celcius and its equivalent in degress celcius.
-if user select option three, abort the process and display a suitable message to that effect.
-the program must repeat the whole processes until user select 3.
-do not allow user to select a value other than 1, 2, or3 from the menu
-declare all needed variables inside the class (globally inside) and out of all methods including main().
import java.util.Scanner;
public class TemperatureConverterMenu {
// returns the temperature in Celcius
public static double toCelcius() {
Scanner sc = new
Scanner(System.in);
System.out.println("Enter
temperature in Fahrenheit: ");
double fTemp=sc.nextDouble();
return (( 5 *(fTemp- 32.0)) / 9.0);
}
public static double toFahrenheit() {
Scanner sc = new
Scanner(System.in);
System.out.println("Enter
temperature in Celcius : ");
double fTemp=sc.nextDouble();
return (9.0/5.0)*fTemp + 32;
}
public static void main(String[] args) {
int ch=0;
Scanner sc = new
Scanner(System.in);
do{
System.out.println("-1-Convert Fahrenheit to Celcius");
System.out.println("-2-Convert Celcius to Fahrenheit");
System.out.println("-3-Quit Program");
ch=sc.nextInt();
switch(ch){
case
1:System.out.println(toCelcius());break;
case
2:System.out.println(toFahrenheit());break;
}
}while(ch<3);
}
}