Question: import java.util.Scanner; public class TemperatureConversion { public static void main( String [] args ) { int userChoice = 0; // User selection: 1, 2, 3

import java.util.Scanner;

public class TemperatureConversion

{

public static void main( String [] args )

{

int userChoice = 0; // User selection: 1, 2, 3

float temperatureFahrenheit = 0; // Fahrenheit temperature

float temperatureCelsius = 0; // Celsius temperature

Scanner input = new Scanner( System.in ); // Create a Scanner to obtain user input

while( userChoice != 3 )

{

System.out.print( "Enter 1 to convert F->C, 2 to convert C->F, 3 to quit: " );

userChoice = input.nextInt(); // Read user input

switch( userChoice )

{

case 1: // Convert Fahrenheit to Celsius

System.out.print( "Enter a Fahrenheit temperature: " );

temperatureFahrenheit = input.nextFloat();

temperatureCelsius = 5F/9F * ( temperatureFahrenheit - 32F );

System.out.println( temperatureFahrenheit + " degrees Fahrenheit is " + temperatureCelsius + " degrees Celsius" );

break;

case 2: // Convert Celsius to Fahrenheit

System.out.print( "Enter a Celsius temperature: " );

temperatureCelsius = input.nextFloat();

temperatureFahrenheit = 9F/5F * temperatureCelsius + 32F;

System.out.println( temperatureCelsius + " degrees Celsius is " + temperatureFahrenheit + " degrees Fahrenheit" );

break;

case 3: // End Program

System.out.println( "Bye Bye" );

break;

default: // Invalid Data Entered

System.out.println( "Invalid Data: You must enter 1, 2, or 3" );

}

}

}

}

Re-design this program using methods. Explain the justification behind your re-design and why using methods is advantageous.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!