0% found this document useful (0 votes)
9 views2 pages

Lab 06

Uploaded by

bushraruhi7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Lab 06

Uploaded by

bushraruhi7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Task 1

You are developing a basic banking application that allows users to withdraw funds from their
accounts. The application should properly manage exceptions using the throws keyword.
Implement the following specifications:

1. Account Class:
o Create a class named Account with these attributes:
▪ accountNumber (String)
▪ balance (double)
o Include a constructor to initialize both the account number and balance.
2. Withdraw Method:
o Implement a method withdraw(double amount) that:
▪ Throws an IllegalArgumentException if the amount to withdraw
exceeds the current balance.
▪ Throws another IllegalArgumentException if the amount is negative.
3. Main Class:
o In your main class, create an instance of Account.
o Prompt the user for the amount they wish to withdraw.
o Use a try-catch block to call the withdraw method and handle the exceptions.
o Print appropriate messages based on the exceptions that are caught

Task 2

 Create a class Character with attributes for name, class type, and level.
 Implement a method createCharacter(String name, String classType, int level)
that:

● Throws IllegalArgumentException if the name is empty.


● Throws IllegalArgumentException if the class type is not one of the predefined options
(e.g., "warrior", "mage").
● Throws IllegalArgumentException if the level is not within a specific range (e.g.,
1-100).
 In the main method, allow users to create characters, handling exceptions to provide
feedback about their input.

You might also like