Question: Task 1 : TemperatureConverter [ 2 5 PTS ] Create a class named TemperatureConverter. In this class, define two methods: celsiusToFahrenheit ( double celsius )
Task : TemperatureConverter PTS
Create a class named TemperatureConverter. In this class, define two methods:
celsiusToFahrenheitdouble celsius: This method takes a temperature in Celsius as input and returns the equivalent value in Fahrenheit. Use the formula Fahrenheit Celsius
fahrenheitToCelsiusdouble fahrenheit: This method takes a temperature in Fahrenheit as input and returns the equivalent value in Celsius. Use the formula Celsius Fahrenheit
Implement exception handling in both methods:
Throw a custom exception named TemperatureBelowAbsoluteZeroException if the input temperature is below absolute zero Celsius: below C Fahrenheit: below F
Task : TemperatureBelowAbsoluteZeroException 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 : Demo 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 trycatch 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
