Question: Question Goal: Create a custom exception and use try - catch statement to handle the exception Assignment: Imagine that you are the director of security
Question
Goal: Create a custom exception and use trycatch statement to handle the exception
Assignment: Imagine that you are the director of security in the Army. It's imperative that operations be authorized only by officers with the correct clearance level. Otherwise, you could have a national security risk.
Begin by creating a custom exception class called InsufficientClearanceException. This class should extend the Exception class and It should invoke the message method of the Exception class.
Next, create a class called ArmyOfficer. The constructor should initialize the userdefined property clearanceLevel with an int between and inclusive. The Armyfficer class should also define a method authorizeOperation that takes an int, requiredClearance. If the requiredClearance is greater than the clearanceLevel the InsufficientClearanceException should be thrown and it should print "Clearance level too low. Authorization denied". If the clearanceLevel is high enough, it should print "Operation authorized. Clearance level: instance of ArmyOfficer accordingly. It should then prompt the officer for the requiredClearance of the operation they are trying to authorize. Using a trycatch statement, call the authorizeOperation method and handle the possible InsufficientClearanceException exception.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
