Lab Tasks 9
Lab Tasks 9
Task 1
In this task, you are given a Java code snippet that performs division between two integers 'a' and
'b'. Your goal is to handle exceptions that may occur during the division operation. You need to test
the code with different inputs for 'a' and 'b' and understand the flow of the program by adding print
statements before and after the division operation. Specifically, you need to add catch blocks for
two types of exceptions: NumberFormatException and ArithmeticException.
Task-3
Bank Account Class Description:
The BankAccount class represents a simple bank account with basic functionalities to manage the
account balance. It is part of the larger Banking System example. The class encapsulates the
account details, such as the account number, account holder's name, and the account balance.
Class: BankAccount
Properties:
- `accountNumber` (String): A string representing the account number of the bank account.
- `accountHolder` (String): A string representing the name of the account holder.
- `balance` (double): A double representing the current balance of the bank account.
Constructor:
- `BankAccount(String accountNumber, String accountHolder, double initialBalance)`: Constructs
a BankAccount object with the provided account number, account holder's name, and initial
balance. The initial balance is the amount of money available in the account when the account is
created.
Public Methods:
- `getAccountNumber() -> String`: Returns the account number associated with the bank account.
- `getAccountHolder() -> String`: Returns the name of the account holder associated with the bank
account.
- `getBalance() -> double`: Returns the current balance of the bank account.
- `deposit(double amount) -> void`: Accepts a double value representing the amount to deposit
and increases the account balance by that amount. It also prints a message to indicate the deposit
transaction.
- `withdraw(double amount) -> void`: Accepts a double value representing the amount to
withdraw. It decreases the account balance by that amount if the account has sufficient funds. If
the withdrawal amount exceeds the account balance, it throws an `InsufficientFundsException`. If
the withdrawal is successful, it also prints a message to indicate the withdrawal transaction.
Exceptions:
- `InsufficientFundsException`: This is a custom exception class that extends the `Exception`. It is
thrown when a withdrawal request is made, and the total balance in the account is less than the
amount to be withdrawn.