Package com.myBank.bankServer
Class Bank
java.lang.Object
com.myBank.bankServer.Bank
- Direct Known Subclasses:
ATM
The
Bank class manages all banking operations, including account creation, deletion,
updates, transfers, and balance management. It acts as the core banking service layer,
maintaining a list of user accounts.
Features:
- Create new user accounts with unique account numbers. - Delete existing accounts with confirmation prompts. - Update user account details such as mobile number or password. - Transfer money between accounts. - Authenticate users and retrieve account details. - Modify account balances for deposits and withdrawals.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<UserAccount> List to store all registered user accounts.protected final ScannerScanner instance for user input. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCreates a new user account with a unique account number.protected voiddeleteAccount(UserAccount account) Deletes an existing user account after confirmation.protected longgetAccountNumber(UserAccount account) Retrieves the account number of the given user account.protected doublegetBalance(UserAccount account) Retrieves the current balance of the given user account.protected UserAccountgetUserAccount(long accountNumber, String password) Retrieves theUserAccountinstance for the given account number and password.protected StringgetUsername(UserAccount account) Retrieves the username associated with the given user account.protected voidtransferMoney(UserAccount account) Transfers money between two user accounts.protected voidupdateAccount(UserAccount account) Updates a user's mobile number or password.protected voidupdateBalance(UserAccount account, double amount, boolean isDeposit) Updates the balance for deposits or withdrawals.protected booleanvalidateUser(long accountNumber, String password) Validates if the given credentials match any registered user.
-
Field Details
-
accounts
List to store all registered user accounts. -
sc
Scanner instance for user input.
-
-
Constructor Details
-
Bank
public Bank()
-
-
Method Details
-
createAccount
protected void createAccount()Creates a new user account with a unique account number.- Generates a random 10-digit account number starting with 607. - Ensures the account number and mobile number are unique. - Verifies password confirmation before account creation.
-
deleteAccount
Deletes an existing user account after confirmation.- Parameters:
account- The user account to delete.
-
updateAccount
Updates a user's mobile number or password.- Parameters:
account- The user account to update.
-
transferMoney
Transfers money between two user accounts.- Parameters:
account- The sender's account.
-
getUserAccount
Retrieves theUserAccountinstance for the given account number and password.- Parameters:
accountNumber- The user's account number.password- The user's password.- Returns:
- The matching
UserAccountornullif not found.
-
validateUser
Validates if the given credentials match any registered user.- Parameters:
accountNumber- The account number.password- The password.- Returns:
trueif valid, otherwisefalse.
-
updateBalance
Updates the balance for deposits or withdrawals.- Parameters:
account- The user account.amount- The transaction amount.isDeposit-truefor deposit,falsefor withdrawal.
-
getUsername
Retrieves the username associated with the given user account.- Parameters:
account- The user account whose username is to be retrieved.- Returns:
- The username of the specified account.
-
getAccountNumber
Retrieves the account number of the given user account.- Parameters:
account- The user account whose account number is to be retrieved.- Returns:
- The account number of the specified account.
-
getBalance
Retrieves the current balance of the given user account.- Parameters:
account- The user account whose balance is to be retrieved.- Returns:
- The current balance of the specified account.
-