Homework 8Exceptions |
Modified: |
The assignment is to implement exceptions for division by zero in the calculator of HW6. The assignment consists of two parts:
- Define a new class divideException that extends the Exception class similar to the counterException class defining:
- a constructor that initializes a string field for an instance of a divideException,
- a method toString that returns the string field.
- Modify Homework 6, the Calculator class:
- throw the divideException when the divisor is zero,
- on a divideException:
- print a message to the console using System.out.println that includes the exception parameter as a string,
- display on the calculator an error message using the updateDisplay method,
- print the stack trace of executions to the console,
- return at the end of the catch
- Test in appletviewer:
- using the Calculator class on division by zero,
- using the Scientific class on division by zero.
- Program listing of Calculator and divideException class definition.
- Command prompt window showing messages for Calculator and Scientific calculator.
- Applet window showing messages for Calculator and Scientific calculator.
- Modify the Calculator onClick method to:
- rethrow the divideException,
- print the stack trace of executions to the console,
- Make any modifications to UserInterface class methods needed to accommodate the previous modification. Print a message and the exception parameter where the exception is handled.
- Test in appletviewer:
- using the Calculator class on division by zero.
- Program listing of Calculator and UserInterface class definition.
- Command prompt window showing messages for Calculator and UserInterface classes.
- Applet window showing messages for Calculator.
- Cover sheet with your name, date, and Homework 8.
- Printouts for parts 1 and 2.