I wrote the code below in Java with TextIO, I need the program to exit when I chose '3' but it still asks to enter the temp? also I need it to give the option at the end "Do you want another conversion Y/N" how to do incorporate this into the program?
import textio.TextIO;
/**
* A program that reads a value that is typed in by the
* user and computes and prints the conversion of that value.
*/
public class TempConvert {
public static void main (String[] args) {
System.out.print("Enter 1 for Fahrenheit to Celsius \n"
+ "Enter 2 for Celsius to Fahrenheit conversion \n"
+ "Enter 3 to exit");
int operation = TextIO.getlnInt();
System.out.print("Enter temperature : ");
float temperature = TextIO.getlnFloat();
float convertedTemperature = 0f;
/*
* Perform temperature conversion using switch statement in Java.
*/
switch (operation) {
//Fahrenheit to Celsius temperature conversion
case 1:
convertedTemperature = ((temperature - 32) * 5) / 9;
System.out.println(temperature + " Fahrenheit " + " in Celsius = "
+ convertedTemperature);
break;
//Celsius to Fahrenheit temperature conversion
case 2:
convertedTemperature = (9 * temperature / 5) + 32;
System.out.println(temperature + " Celsius " + " in Fahrenheit = "
+ convertedTemperature);
break;
//case 3 to exit program
case 3:
System.out.println("\nProgram will now terminate. Goodbye!");
System.exit(0);
default: // optional
System.out.println("Enterd temerature is Invalid");
break; // optional
}
}
}
sectetu
sectetur adipiscingsectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. D
seUnlock access to this and over
10,000 step-by-step explanations
Have an account? Log In
sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus
sectetur adipiscing elit. Nam lac
sectetur adipiscing elit.
sectetur
sec
sectetur adipiscing elit. Nam lacinia pu