Question: Task 1 : TemperatureConverter [ 2 5 PTS ] Create a class named TemperatureConverter. In this class, define two methods: celsiusToFahrenheit ( double celsius )

Task 1: TemperatureConverter [25 PTS]
Create a class named TemperatureConverter. In this class, define two methods:
celsiusToFahrenheit(double celsius): This method takes a temperature in Celsius as input and returns the equivalent value in Fahrenheit. Use the formula Fahrenheit =(Celsius *9/5)+32.
fahrenheitToCelsius(double fahrenheit): This method takes a temperature in Fahrenheit as input and returns the equivalent value in Celsius. Use the formula Celsius =(Fahrenheit -32)*5/9.
Implement exception handling in both methods:
Throw a custom exception named TemperatureBelowAbsoluteZeroException if the input temperature is below absolute zero (Celsius: below -273.15C, Fahrenheit: below -459.67F)
Task 2: TemperatureBelowAbsoluteZeroException [10 PTS]
Create a custom exception class named TemperatureBelowAbsoluteZeroException that extends the RuntimeException class. This exception represents the scenario where the user enters a temperature below absolute zero.
Task 3: Demo [25 PTS]
Create a Demo class and in your main method, prompt the user to enter the temperature (Celsius or Fahrenheit) and the desired conversion (C to F or F to C):
Use a loop to allow repeated conversions until the user exits.
Read user input using Scanner.
Use a try-catch block to handle potential exceptions:
Inside the try block, call the appropriate conversion method (celsiusToFahrenheit or fahrenheitToCelsius) based on the user's selection.
In the catch block (catching TemperatureBelowAbsoluteZeroException), display an appropriate error message to the user and prompt them to enter a valid temperature.

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 Programming Questions!