Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment : The first lab assignment is an exercise in the use of the exception and handling of exceptions. You will write a main method

Assignment:

The first lab assignment is an exercise in the use of the exception and handling of exceptions. You will write a main method to test the Triangle class which I have written. Triangle takes doubles as constructor arguments for the A and B sides of a right triangle and calculates the hypotenuse. However it does nothing to handle the situation where a user enters data which is negative, zero or non numeric. Your main should handle these situations.

Input Commands:

A enter value for side A

B enter value for side B

C calculate

Q quit the program

The program will repeat itself in order to make it easier to test. You will create a new object of the Triangle class for each test.

Your task today is to write 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

Input command, not A, B, C or Q

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

Testing:

Test your program with the following test cases;

A

A

A

A

B

A

B

X

Q

3

3

0

s

s

3

3

B

B

B

C

C

4

0

3

C

C

C

In all cases of invalid input the program should ask for only the input values that were invalid and should continue with the values that were correct. The program should never crash!

Files:

Main.java supplied by you

Triangle.java supplied by blackboard

Lab Exercise 01.2

Handle exceptions

Assignment:

The next lab assignment is another exercise in the use of the exception and handling of exceptions. You will write a main method to test the Quadratic class which I have written. Quadratic takes doubles as constructor arguments for the a, b and c coefficients of a quadratic equation and calculates the two values for X. However it does nothing to handle the situation where a user enters data which either includes a value of 0.0 for a or is non numeric. The program should always display two values as the result since a quadratic equation, by definition, always has two values as the solution even when the values are identical.

The program will repeat itself in order to make it easier to test.

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 develop 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 will not terminate but will inform the user of the specific error and should re-request the input value which was in error

Testing:

Test your program with Main.java supplied by blackboard.

The program should never crash!

Files:

Main.java supplied by blackboard

Quadratic.java supplied by you

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

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions

Question

List the five functions of an MIS.

Answered: 1 week ago