Class Bank

java.lang.Object
com.myBank.bankServer.Bank
Direct Known Subclasses:
ATM

public class Bank extends Object
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 Details

    • accounts

      private final List<UserAccount> accounts
      List to store all registered user accounts.
    • sc

      protected final Scanner 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

      protected void deleteAccount(UserAccount account)
      Deletes an existing user account after confirmation.
      Parameters:
      account - The user account to delete.
    • updateAccount

      protected void updateAccount(UserAccount account)
      Updates a user's mobile number or password.
      Parameters:
      account - The user account to update.
    • transferMoney

      protected void transferMoney(UserAccount account)
      Transfers money between two user accounts.
      Parameters:
      account - The sender's account.
    • getUserAccount

      protected UserAccount getUserAccount(long accountNumber, String password)
      Retrieves the UserAccount instance for the given account number and password.
      Parameters:
      accountNumber - The user's account number.
      password - The user's password.
      Returns:
      The matching UserAccount or null if not found.
    • validateUser

      protected boolean validateUser(long accountNumber, String password)
      Validates if the given credentials match any registered user.
      Parameters:
      accountNumber - The account number.
      password - The password.
      Returns:
      true if valid, otherwise false.
    • updateBalance

      protected void updateBalance(UserAccount account, double amount, boolean isDeposit)
      Updates the balance for deposits or withdrawals.
      Parameters:
      account - The user account.
      amount - The transaction amount.
      isDeposit - true for deposit, false for withdrawal.
    • getUsername

      protected String getUsername(UserAccount account)
      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

      protected long getAccountNumber(UserAccount account)
      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

      protected double getBalance(UserAccount account)
      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.