0% found this document useful (0 votes)
6 views

Lab Task 07.Docx

Uploaded by

bushraruhi7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Lab Task 07.Docx

Uploaded by

bushraruhi7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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>.

You might also like