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 try-catch 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 user-defined property clearanceLevel with an int between 1 and 5, inclusive. The Army0fficer 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 try-catch statement, call the authorizeOperation method and handle the possible InsufficientClearanceException exception.
Question Goal: Create a custom exception and use

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