Oop Assignment (Exception Handling)
Oop Assignment (Exception Handling)
_______________________________________________________________________
Question No 2: Identify abstract class/ class / interface in exception handling class hierarchy?
A method named M1 that accepts a double variable as argument and returns its square root.
The method should throw the NegativeNumberException exception defined above.
The main method to prompt the user to enter a number and then to call the method M1
(insert a try-catch block to handle the NegativeNumberException exception)
Question No 4:
Write a program that calculates the average of N integers. The program should prompt the
user to enter the value for N and then afterward must enter all N numbers. If the user enters
a negative value for N, then an exception should be thrown (and caught) with the message “
N must be positive.” If there is any exception as the user is entering the N numbers, an error
message should be displayed, and the user prompted to enter the number again