Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. try, catch and throw statements must be used in this assignment, to check for errors.
  2. High and low temperature inputs must be a decimal or integer.
  3. High temperature must be greater than or equal to the low temperature.
  4. Ask for high temperature first.
  5. If high temperature input is not a decimal or integer, its an error, and ask the user to try again.
    1. Use Exception handling to check for error here (hint: catch InputMismatchException).
  6. Ask for low temperature after high temperature.
    1. Low temperature input has the same rules for exception handling as high temperature in step #4.
  7. If the low temperature is greater than the high temperature, its an error, and start over (both high & low temperatures must be re-input)
    1. 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)
  8. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions