Your objective is to create a Java program that facilitates the conversion between Celsius and Fahrenheit temperatures. The user should be able to choose the conversion direction (from Celsius to Fahrenheit or vice versa) and then input the temperature value for conversion.
For the sake of this challenge, you can use the following conversion formulas:
- Celsius to Fahrenheit:
(Celsius × 9/5) + 32 - Fahrenheit to Celsius:
(Fahrenheit - 32) × 5/9
Your program should:
- Prompt the user to select a conversion direction.
- Accept the temperature in the selected format.
- Display the converted temperature.
1: Celsius to Fahrenheit 2: Fahrenheit to Celsius Choose conversion direction: 1 Enter temperature in Celsius: 25 Temperature in Fahrenheit: 77.0
- Use
Scannerclass from thejava.utilpackage for user input. - Ensure you handle potential exceptions or invalid inputs gracefully.
- The input temperature is a floating-point number in the range
-273.15(absolute zero) to10^5. - You should round off the converted temperature to 2 decimal places.
Set forth into the world of Java and take on this enlightening challenge!