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 Scanner
Scanner instance for user input. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Creates a new user account with a unique account number.protected void
deleteAccount
(UserAccount account) Deletes an existing user account after confirmation.protected long
getAccountNumber
(UserAccount account) Retrieves the account number of the given user account.protected double
getBalance
(UserAccount account) Retrieves the current balance of the given user account.protected UserAccount
getUserAccount
(long accountNumber, String password) Retrieves theUserAccount
instance for the given account number and password.protected String
getUsername
(UserAccount account) Retrieves the username associated with the given user account.protected void
transferMoney
(UserAccount account) Transfers money between two user accounts.protected void
updateAccount
(UserAccount account) Updates a user's mobile number or password.protected void
updateBalance
(UserAccount account, double amount, boolean isDeposit) Updates the balance for deposits or withdrawals.protected boolean
validateUser
(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 theUserAccount
instance for the given account number and password.- Parameters:
accountNumber
- The user's account number.password
- The user's password.- Returns:
- The matching
UserAccount
ornull
if not found.
-
validateUser
Validates if the given credentials match any registered user.- Parameters:
accountNumber
- The account number.password
- The password.- Returns:
true
if valid, otherwisefalse
.
-
updateBalance
Updates the balance for deposits or withdrawals.- Parameters:
account
- The user account.amount
- The transaction amount.isDeposit
-true
for deposit,false
for 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.
-