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

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.
Writing Task 1. in what ways are three temperature scales the same ? 2. In what...
Writing Task 1. in what ways are three temperature scales the same ? 2. In what ways are the three temperature scales different ? 3. At approximately what temperature would Celsius and Fahrenheit thermometer register the same reading ? 4. what is absolute zero temperature ? explain
The temperature function (in degrees Fahrenheit) in a three dimensional space is given by T(x, y,...
The temperature function (in degrees Fahrenheit) in a three dimensional space is given by T(x, y, z) = 3x + 6y - 6z + 1. A bee is constrained to live on a sphere of radius 3 centered at the origin. In other words, the bee cannot fly off of this sphere. What is the coldest temperature that the bee can experience on this sphere? Where does this occur? What is the hottest temperature that the bee can experience on...
 Describe what is the vapour pressure? When the temperature is 100 degree Celsius, what is the vapour pressure of water?
Describe what is the vapour pressure? When the temperature is 100 degree Celsius, what is the vapour pressure of water?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT