Question

In: Computer Science

Temperature Conversion Menu (100 pts) The three common temperature scales are Celsius, Fahrenheit and Kelvin. The...

Temperature Conversion Menu (100 pts)

The three common temperature scales are Celsius, Fahrenheit and Kelvin. The conversion formulae for each of the scales is shown below (where °C, °F and K represent the temperatures in degrees Celsius, degrees Fahrenheit and Kelvin respectively):

Celsius to Fahrenheit: °F = (9.0/5) ´ (°C) + 32

Celsius to Kelvin: K = °C + 273.15

Kelvin to Celsius: °C = K – 273.15

Kelvin to Fahrenheit: °F = (9.0/5) ´ (K – 273.15) + 32

Fahrenheit to Celsius: °C = (5.0/9) ´ (°F – 32)

Fahrenheit to Kelvin: K = (5.0/9) ´ (°F – 32) + 273.15

Write a program that can convert the temperature using the given formulae.

Your code should:

  1. Generate a menu for displaying the menu conversion options.
  • Menu should be displayed using a void method that accepts no parameters
  • Choices are:          1 – convert from Celsius to Fahrenheit

2 – convert from Celsius to Kelvin

3 – convert from Kelvin to Celsius

4 – convert from Kelvin to Fahrenheit

5 – convert from Fahrenheit to Celsius

6 – convert from Fahrenheit to Kelvin

7 – quit the program

  1. Ask the user to select a value (from the menu above) that indicates their choice:
  • Use a while loop to ensure that the user only enters a value between 1 and 7. (In other words, force the user to re-enter the value if the values are outside that range).

  1. Ask the user to enter the temperature if the selection is between 1 and 6.
    • Make sure to initialize temperature to 0 when you declare it.
  1. Perform the necessary conversion based on the selection that was made.
  • The selections should be managed by a switch statement
  • Cases 1-6 in the switch statement should then redirect to a conversion method that performs the calculations. Each method here should be a value returning method that accepts 1 parameter (the temperature) and returns a value.
    • Case 1 should include a method call for converting Celsius to Fahrenheit
    • Case 2 should include a method call for converting Celsius to Kelvin
    • Case 3 should include a method call for converting Kelvin to Celsius
    • Case 4 should include a method call for converting Kelvin to Fahrenheit
    • Case 5 should include a method call for converting Fahrenheit to Celsius
    • Case 6 should include a method call for converting Fahrenheit to Kelvin
    • Case 7 does not require a method; only an output to indicate that the program is ending. (No default case is needed)
  • Note: NONE of your value returning methods should prompt the user for the temperature (as this would have already been done in part 3).

  1. Loop from step 1, using a do while loop which would allow the user to enter another option. The program should only end when the user presses 7. (In other words, the loop runs while the choice is not equal to 7.)

Samples of the output are shown below. (Note, match the wording as closely as possible and accomplish the same tasks.)

Please select an option below (1 to 7):
1. Convert from Celsius to Fahrenheit
2. Convert from Celsius to Kelvin
3. Convert from Kelvin to Celsius
4. Convert from Kelvin to Fahrenheit
5. Convert from Fahrenheit to Celsius
6. Convert from Fahrenheit to Kelvin
7. Quit
Enter choice: 8
Invalid entry. Renter choice: 1
Enter the temperature: 100
100.0 degrees Celsius is 212.0 degrees Fahrenheit


Please select an option below (1 to 7):
1. Convert from Celsius to Fahrenheit
2. Convert from Celsius to Kelvin
3. Convert from Kelvin to Celsius
4. Convert from Kelvin to Fahrenheit
5. Convert from Fahrenheit to Celsius
6. Convert from Fahrenheit to Kelvin
7. Quit
Enter choice: 2
Enter the temperature: 0
0.0 degrees Celsius is 273.15 Kelvin


Please select an option below (1 to 7):
1. Convert from Celsius to Fahrenheit
2. Convert from Celsius to Kelvin
3. Convert from Kelvin to Celsius
4. Convert from Kelvin to Fahrenheit
5. Convert from Fahrenheit to Celsius
6. Convert from Fahrenheit to Kelvin
7. Quit
Enter choice: 3
Enter the temperature: -40
-40.0 degrees Fahrenheit is -40.0 degrees Celsius


Please select an option below (1 to 7):
1. Convert from Celsius to Fahrenheit
2. Convert from Celsius to Kelvin
3. Convert from Kelvin to Celsius
4. Convert from Kelvin to Fahrenheit
5. Convert from Fahrenheit to Celsius
6. Convert from Fahrenheit to Kelvin
7. Quit
Enter choice: 4
Enter the temperature: 70
70.0 degrees Fahrenheit is 294.26111111111106 Kelvin


Please select an option below (1 to 7):
1. Convert from Celsius to Fahrenheit
2. Convert from Celsius to Kelvin
3. Convert from Kelvin to Celsius
4. Convert from Kelvin to Fahrenheit
5. Convert from Fahrenheit to Celsius
6. Convert from Fahrenheit to Kelvin
7. Quit
Enter choice: 5
Enter the temperature: 100
100.0 Kelvin is -173.14999999999998 degrees Celsius


Please select an option below (1 to 7):
1. Convert from Celsius to Fahrenheit
2. Convert from Celsius to Kelvin
3. Convert from Kelvin to Celsius
4. Convert from Kelvin to Fahrenheit
5. Convert from Fahrenheit to Celsius
6. Convert from Fahrenheit to Kelvin
7. Quit
Enter choice: 6
Enter the temperature: 100
100.0 Kelvin is -279.66999999999996 degrees Fahrenheit


Please select an option below (1 to 7):
1. Convert from Celsius to Fahrenheit
2. Convert from Celsius to Kelvin
3. Convert from Kelvin to Celsius
4. Convert from Kelvin to Fahrenheit
5. Convert from Fahrenheit to Celsius
6. Convert from Fahrenheit to Kelvin
7. Quit
Enter choice: 7
Ok bye!

Solutions

Expert Solution

Following java program provides menu driven program to convert temperature in one unit to another based on choice.

PFB source code with sample output.

Note : No language was specified, so wrote in java.

--------------------------
TemperatureConversion.java
--------------------------
import java.util.Scanner;

public class TemperatureConversion {


public static double celsiusToFahrenheit(double temperature){
//Celsius to Fahrenheit: °F = (9.0/5) ´ (°C) + 32

return ((9.0/5)*temperature+32);


}

public static double celsiusToKelvin(double temperature){
//Celsius to Kelvin: K = °C + 273.15
return (temperature + 273.15);

}

public static double kelvinToCelsius(double temperature){
//Kelvin to Celsius: °C = K – 273.15
return (temperature - 273.15);   

}

public static double kelvinToFahrenheit(double temperature){
//Kelvin to Fahrenheit: °F = (9.0/5) ´ (K – 273.15) + 32
return ((9.0/5) * (temperature-273.15) + 32);

}

public static double fahrenheitToCelsius(double temperature){
//Fahrenheit to Celsius: °C = (5.0/9) ´ (°F – 32)
return ((5.0/9)*(temperature-32));

}

public static double fahrenheitToKelvin(double temperature){
//Fahrenheit to Kelvin: K = (5.0/9) ´ (°F – 32) + 273.15
return ((5.0/9)*(temperature-32)+273.15);

}
public static void menu(){

int choice;
double temperature=0;

Scanner sc = new Scanner(System.in);

do{
  
System.out.println("\n\n");
System.out.println("Please select an option below (1 to 7):");
System.out.println("1 - Convert from Celsius to Fahrenheit");
System.out.println("2 - Convert from Celsius to Kelvin");
System.out.println("3 - Convert from Kelvin to Celsius");
System.out.println("4 - Convert from Kelvin to Fahrenheit");
System.out.println("5 - Convert from Fahrenheit to Celsius");
System.out.println("6 - Convert from Fahrenheit to Kelvin");
System.out.println("7 - Quit the program");

System.out.print("Enter choice: ");
choice = sc.nextInt();

while(choice<1 || choice>7){
  
System.out.print("Invalid entry. Renter choice: ");
choice = sc.nextInt();

}
if(choice<=6){
System.out.print("Enter the temperature: ");
temperature = sc.nextDouble();
}

double convertedTemperature;

switch(choice){

case 1: convertedTemperature = celsiusToFahrenheit(temperature);
System.out.println(temperature + " degrees Celsius is " + convertedTemperature + " degrees Fahrenheit");
break;
case 2: convertedTemperature = celsiusToKelvin(temperature);
System.out.println(temperature + " degrees Celsius is " + convertedTemperature + " Kelvin");
break;
case 3: convertedTemperature = kelvinToCelsius(temperature);
System.out.println(temperature + " Kelvin is " + convertedTemperature + " degrees Celsius");
break;
case 4: convertedTemperature = kelvinToFahrenheit(temperature);
System.out.println(temperature + " Kelvin is " + convertedTemperature + " degrees Fahrenheit");
break;
case 5: convertedTemperature = fahrenheitToCelsius(temperature);
System.out.println(temperature + " degrees Fahrenheit is " + convertedTemperature + " degrees Celsius");
break;
case 6: convertedTemperature = fahrenheitToKelvin(temperature);
System.out.println(temperature + " degrees Fahrenheit is " + convertedTemperature + " Kelvin");
break;
case 7: System.out.println("Ok bye!");
return;
}
}while(true);


}

public static void main(String[] args) {

//calling menu
menu();

}
}
--------------------------

---------------------
sample output
---------------------


---------------------


Let me know, if you face any issue.


Related Solutions

Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin...
Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin Newton Your program should take a character which represents the temperature to convert from and a value to be converted to using the following specification: C - Celsius K - Kelvin N - Newton In addition your program should take in the following character to exit the program: X - eXit the program The numeric input for your program should be of type double....
(a) At what temperature do the Fahrenheit and Celsius scales have the same numerical value? (b)...
(a) At what temperature do the Fahrenheit and Celsius scales have the same numerical value? (b) The Fahrenheit and Kelvin scales? (c) Describe the basis of each of these three temperature scales. The two cryogenic liquids I use in the lab are liquid nitrogen and liquid helium. What are the boiling points of those two liquids (e) in Fahrenheit? (f) in Kelvins?
Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The...
Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The table should include rows for all temperatures between 0 and 100 degrees Celsius that are multiples of 10 degrees Celsius. Include appropriate headings on your columns. The formula for converting between degrees Celsius and degrees Fahrenheit can be found on the internet. Python 3
At what temperatures values are the following scales the same? (a) The Fahrenheit and the Celsius   ...
At what temperatures values are the following scales the same? (a) The Fahrenheit and the Celsius    (b) The Celsius and the Kelvin     (c) The Fahrenheit and the Kelvin  
(Python) Write a code converting degrees in Fahrenheit to degrees Kelvin, using this conversion equation conversion...
(Python) Write a code converting degrees in Fahrenheit to degrees Kelvin, using this conversion equation conversion from degrees Fahrenheit to Celcius: ? = (? − 32) x 5/9 and then to degrees Kelvin: ? = ? + 273.15 with the following properties 1) the code should take into account that temperature in degrees Kelvin cannot be smaller than zero. In other words, your code should return 0 Kelvin as the smallest temperature for any input value of degrees Fahrenheit). 2)...
Convert the boiling temperature of gold, 2966 °C, into degrees Fahrenheit and kelvin.
Convert the boiling temperature of gold, 2966 °C, into degrees Fahrenheit and kelvin.  
Instructions Write a program in C# that converts a temperature given in Fahrenheit to Celsius. Allow...
Instructions Write a program in C# that converts a temperature given in Fahrenheit to Celsius. Allow the user to enter values for the original Fahrenheit value. Display the original temperature and the formatted converted value. Use appropriate value returning methods for entering (input), calculating, and outputting results.
Write a function in bash that takes an input temperature (Celsius or Fahrenheit) from the user...
Write a function in bash that takes an input temperature (Celsius or Fahrenheit) from the user converts that temperature Celsius to Fahrenheit, Fahrenheit to Celsius, Celsius to Kelvin and Fahrenheit to Kelvin
****USING BASH**** Write a function that takes an input temperature (Celsius or Fahrenheit) from the user...
****USING BASH**** Write a function that takes an input temperature (Celsius or Fahrenheit) from the user converts that temperature Celsius to Fahrenheit, Fahrenheit to Celsius, Celsius to Kelvin and Fahrenheit to Kelvin.
Write in java Q 4.Centigrade and Fahrenheit are two scales to measure temperature. Write a program...
Write in java Q 4.Centigrade and Fahrenheit are two scales to measure temperature. Write a program that that prompts the user to enter Centigrate and then print the Fahrenheit. Use following formula for conversion. Fahrenheit = Centigrade*1.8 +   32 ; Q. 7 Write a program to calculate the bill of a customer. The program will -           Prompt the employee to enter the monthly plan fees. -           Prompt the employee to enter the rate per additional minute. -          Print the bill...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT