Task 1
Here are some lab tasks on user-defined exceptions that could help students understand how to
define and handle custom exceptions:
Bank Account Management
○ Create a BankAccount class with a method to withdraw money.
○ Define custom exceptions like InsufficientFundsException and
NegativeAmountException.
○ If a user tries to withdraw more than the balance, throw
InsufficientFundsException.
○ If the amount is negative, throw NegativeAmountException.
Task 2
Age Verification for Voting for USA
● Write a program that checks if a user is eligible to vote by age.
● Define a custom exception UnderageException.
● If the user's age is below 18, throw UnderageException with a message about the
eligibility criteria.
Task 3
Generic Box Class
● Create a Box<T> class that can store any type of object.
● Add methods to set and get the object from the box.
● Test this class by creating Box instances for different types, such as Box<Integer>,
Box<String>, and Box<Double>.