Question: In Java Assignment : The next lab assignment is another exercise in the use of the exception and handling of exceptions. There is another simple

In Java

Assignment:

The next lab assignment is another exercise in the use of the exception and handling of exceptions. There is another simple calculation program listed below, which takes decimal values (doubles) as input for the a, b and c coefficients of a quadratic equation and calculates the two values for X. The program should always display two values as the result; a quadratic equation always has two values as the solution even when they are identical.

The program should repeat itself if the user wishes; this makes it easier to test. Values for A and B will be cleared to 0 (zero) after each calculation.

However it does nothing to handle the situation where a user enters data which is non-double or even non numeric. Your task today is to modify that program to handle the bad input situation with the use of exception handling. Bad inputs are:

Non-numeric values where numeric values are expected

Any input that causes the output to be NaN (Not a Number)

Any input that causes the output to be INFINITY

The program should not terminate but should inform the user of the specific error and should re-request the input value which was in error

Testing:

Test your program with the following input;

a. Non-numeric value when double is expected.

b. A = 0

c. Values which result in NaN or INFINITY for answers.

d. Correct input

In all cases the program should ask for only the input values that were invalid and should continue with the values that were correct. The request for a corrected value should be repeated as many times as the user inputs illegal values.

The program should never crash!

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