Class Bank

java.lang.Object
com.atmbanksimulator.Bank

public class Bank extends Object

ATM Simulator - Bank: Bank Manager

The Bank class represents the bank system that manages account authentication and operations. It acts as an intermediary between the UIModel and the SQLite database, that is responsible for all data operations through BankAccount and SQLite.

Version:
3.0
Author:
D'Souza, C. J.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initialises the Bank and establishes a connection to the SQLite database.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    checkPin(String userInput)
    Checks whether the given input matches the logged in account's PIN.
    boolean
    deposit(float amount)
    Deposits the given amount into the logged in account.
    boolean
    deposit_transferred(String accountNumber_receiver, float amount)
    Credits the given amount into a receiver's account as part of a transfer.
    getAccountDetails(String accountNumber)
    Retrieves all account and customer details for the given account number.
    float
    Returns the current balance of the logged in account.
    getName(String accountNumber)
    Retrieves the full name of the customer associated with the given account number.
    Retrieves the full transaction history for the given account number.
    float
    getWithdrawalLimit(String accountNumber)
    Retrieves the one-time withdrawal limit for the given account.
    boolean
    Checks whether a user is currently logged in.
    boolean
    login(String accountNumber, String password)
    Attempts to log in with the given account number and password.
    boolean
    login_AccountExist(String accountNumber)
    Checks whether an account with the given number exists in the database.
    void
    Logs out the currently logged in account by setting loggedInAccount to null.
    setUpBankAccount(String accNumber, String accPasswd, float balance, SQLite sqlite)
    Method to create a new BankAccount2 instance.
    void
    updatePin(String accountNumber, String newPin)
    Updates the PIN for the given account in both the database and the in memory account.
    void
    updatePlan(String accountNumber, String type, String tier, float withdrawalLimit)
    Updates the account type, tier, and withdrawal limit for the given account.
    void
    updateWithdrawalLimit(String accountNumber, float withdrawalLimit)
    Updates the one-time withdrawal limit for the given account.
    boolean
    withdraw(float amount)
    Withdraws the given amount from the logged in account.
    boolean
    withdraw_transferred(String accountNumber_receiver, float amount)
    Debits the given amount from the logged in account as part of a transfer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Bank

      public Bank()
      Initialises the Bank and establishes a connection to the SQLite database.
  • Method Details

    • setUpBankAccount

      public BankAccount setUpBankAccount(String accNumber, String accPasswd, float balance, SQLite sqlite)
      Method to create a new BankAccount2 instance.
      Parameters:
      accNumber - the account number
      accPasswd - the account PIN/password
      balance - the current balance
      sqlite - the SQLite connection to use
      Returns:
      a new BankAccount object
    • login_AccountExist

      public boolean login_AccountExist(String accountNumber)
      Checks whether an account with the given number exists in the database.
      Parameters:
      accountNumber - the account number to check
      Returns:
      true if the account exists, false otherwise
    • login

      public boolean login(String accountNumber, String password)
      Attempts to log in with the given account number and password. Logs out any previously logged in account before attempting login.
      Parameters:
      accountNumber - the account number
      password - the PIN/password to verify
      Returns:
      true if login is successful, false otherwise
    • logout

      public void logout()
      Logs out the currently logged in account by setting loggedInAccount to null.
    • loggedIn

      public boolean loggedIn()
      Checks whether a user is currently logged in.
      Returns:
      true if an account is logged in, false otherwise
    • deposit

      public boolean deposit(float amount)
      Deposits the given amount into the logged in account.
      Parameters:
      amount - the amount to deposit
      Returns:
      true if deposit was successful, false if not logged in
    • deposit_transferred

      public boolean deposit_transferred(String accountNumber_receiver, float amount)
      Credits the given amount into a receiver's account as part of a transfer.
      Parameters:
      accountNumber_receiver - the account number to receive the funds
      amount - the amount to credit
      Returns:
      true if successful, false if not logged in
    • getWithdrawalLimit

      public float getWithdrawalLimit(String accountNumber)
      Retrieves the one-time withdrawal limit for the given account.
      Parameters:
      accountNumber - the account number to query
      Returns:
      the withdrawal limit, or 0 if not logged in
    • updateWithdrawalLimit

      public void updateWithdrawalLimit(String accountNumber, float withdrawalLimit)
      Updates the one-time withdrawal limit for the given account.
      Parameters:
      accountNumber - the account number to update
      withdrawalLimit - the new withdrawal limit
    • withdraw

      public boolean withdraw(float amount)
      Withdraws the given amount from the logged in account.
      Parameters:
      amount - the amount to withdraw
      Returns:
      true if withdrawal was successful, false otherwise
    • withdraw_transferred

      public boolean withdraw_transferred(String accountNumber_receiver, float amount)
      Debits the given amount from the logged in account as part of a transfer.
      Parameters:
      accountNumber_receiver - the receiver's account number (for transaction record)
      amount - the amount to debit
      Returns:
      true if successful, false otherwise
    • getBalance

      public float getBalance()
      Returns the current balance of the logged in account.
      Returns:
      the balance, or -1 if not logged in
    • getName

      public String getName(String accountNumber)
      Retrieves the full name of the customer associated with the given account number.
      Parameters:
      accountNumber - the account number to look up
      Returns:
      the customer's full name in uppercase, or empty string if not logged in
    • getTransactionHistory

      public ArrayList<ArrayList<String>> getTransactionHistory(String accountNumber)
      Retrieves the full transaction history for the given account number.
      Parameters:
      accountNumber - the account number to query
      Returns:
      a list of transaction records, each as a list of strings, or null if not logged in
    • getAccountDetails

      public ArrayList<String> getAccountDetails(String accountNumber)
      Retrieves all account and customer details for the given account number.
      Parameters:
      accountNumber - the account number to query
      Returns:
      a list of detail strings in a fixed order, or null if not logged in
    • checkPin

      public boolean checkPin(String userInput)
      Checks whether the given input matches the logged in account's PIN.
      Parameters:
      userInput - the PIN entered by the user
      Returns:
      true if the PIN matches, false otherwise
    • updatePin

      public void updatePin(String accountNumber, String newPin)
      Updates the PIN for the given account in both the database and the in memory account.
      Parameters:
      accountNumber - the account number to update
      newPin - the new PIN string
    • updatePlan

      public void updatePlan(String accountNumber, String type, String tier, float withdrawalLimit)
      Updates the account type, tier, and withdrawal limit for the given account.
      Parameters:
      accountNumber - the account to update
      type - the new account type (Basic or Student)
      tier - the new account tier (Normal, Pro, or Prime)
      withdrawalLimit - the new withdrawal limit