Question
Assignment: Exception Handling Write a program that takes two temperatures from the user, high and low, and outputs the difference. There are strict requirements: try,
Assignment: Exception Handling
Write a program that takes two temperatures from the user, high and low, and outputs the difference. There are strict requirements:
- try, catch and throw statements must be used in this assignment, to check for errors.
- High and low temperature inputs must be a decimal or integer.
- High temperature must be greater than or equal to the low temperature.
- Ask for high temperature first.
- If high temperature input is not a decimal or integer, its an error, and ask the user to try again.
- Use Exception handling to check for error here (hint: catch InputMismatchException).
- Ask for low temperature after high temperature.
- Low temperature input has the same rules for exception handling as high temperature in step #4.
- If the low temperature is greater than the high temperature, its an error, and start over (both high & low temperatures must be re-input)
- Use Exception handling to check for error here (hint: create a method that throws IllegalArgumentException specially designed to check for low temperature greater than high, and throw the error)
- Once high & low temperatures are input correctly, and high is greater than or equal to low, output the temperature difference, and quit
Here is an example to follow, example of what i need done, need our own code
What was the high temperature today? Thirty nine and a half
Incorrect high temperature, must be a decimal or integer. Try again
What was the high temperature today? 39.5
What was the low temperature today? 13.g
Incorrect low temperature, must be a decimal or integer. Try again
What was the low temperature today? 133
High temperature must be greater than or equal to the low temperature. Try again
What was the high temperature today? 13.3
What was the low temperature today? 13.4
High temperature must be greater than or equal to the low temperature. Try again
What was the high temperature today? 39.5
What was the low temperature today? 13.3
The temperature difference was 26.2
There is an example of what to do above, please write code for this assignment, for my java programming ll class!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started