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

Assignment 2

Uploaded by

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

Assignment 2

Uploaded by

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

Assignment 2

Submission and Deadline:


1. You must submit a report that includes screenshots and explanations of your code. If the
report is not uploaded, you will receive 0 points. The deadline for submission is 30st
December, 9:00.
2. You are required to defend your report. During the defense, you must explain your code
and answer questions about your implementation.
Task:
1. Create a class BankAccount with the following private fields:
o accountNumber (String)
o accountHolderName (String)
o balance (double)
2. Add the following methods to the BankAccount class:
o A public getter for accountNumber (the account number cannot be changed after
the object is created).
o Public getters and setters for accountHolderName.
o Public getter for balance.
o A method deposit(double amount) that adds money to the account. Ensure the
deposit amount is positive. If a negative value is passed, display an error message
like:
"Deposit amount must be positive."
o A method withdraw(double amount) that deducts money from the balance. Ensure
the withdrawal amount is positive and does not exceed the current balance. If
either condition is not met, display an appropriate error message.
3. Create a class Bank with the following private fields:
o bankName (String)
o accounts (ArrayList of BankAccount objects)
4. Add the following methods to the Bank class:
o Public getter and setter for bankName.
o A method addAccount(BankAccount account) that adds a new account to the
bank. Ensure no two accounts have the same accountNumber. If a duplicate is
detected, display an error message like:
"An account with this account number already exists."
o A method findAccount(String accountNumber) that searches for an account by its
number and returns the corresponding BankAccount object. If no account is
found, return null.
o A method displayAllAccounts() that prints the details of all accounts in the bank.
5. In the main method:
o Create a Bank object.
o Add at least three BankAccount objects to the bank.
o Perform various operations such as deposits, withdrawals, and searching for
accounts.
o Display all accounts at the end.
Requirements for Homework Submission:
 Use proper encapsulation (all fields must be private).
 Include validation for deposits, withdrawals, and account number uniqueness.
 Use meaningful method names and comments to explain the code.

Scoring:
 Meeting all task requirements earns you a maximum of 80 points.
 To score higher, you must implement extra functionality. However, the same extra
functionality can only be implemented by at most two students. You must communicate
with your groupmates to ensure this rule is followed.

Example of Extra Functionality: Find Accounts with Minimum Balance:

Add a method in the bank class (if implemented) to find all accounts with a balance greater than
or equal to a given amount.

Example Input: Minimum Balance: 500

Example Output:
Accounts with balance >= $500:
Account ID: 101, Name: Alice, Balance: $750
Account ID: 102, Name: Bob, Balance: $500

Good Luck!!!

You might also like