Class BankAccount

java.lang.Object
com.atmbanksimulator.BankAccount

public class BankAccount extends Object

ATM Simulator - Bank Account

The BankAccount class represents a single bank account within the ATM system. It stores the account credentials and balance, and provides methods to deposit, withdraw, and transfer funds. All balance changes are sent to the SQLite database and recorded as transactions.

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

    Constructors
    Constructor
    Description
    Default constructor.
    BankAccount(String a, String p, float b, SQLite sqlite)
    Constructs a BankAccount2 with the given credentials, balance, and database connection.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    deposit(float amount)
    Deposits the given amount into this account.
    boolean
    deposit_transferred(String accountNumber_receiver, float amount)
    Credits the given amount to a receiver's account as part of an incoming transfer.
    Returns the PIN/password associated with this account.
    float
    Returns the current in memory balance for this account.
    void
    Updates the in memory PIN/password for this account.
    boolean
    withdraw(float amount)
    Withdraws the given amount from this account.
    boolean
    withdraw_transferred(String accountNumber_receiver, float amount)
    Debits the given amount from this account as part of an outgoing transfer.

    Methods inherited from class java.lang.Object

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

    • BankAccount

      public BankAccount()
      Default constructor. Creates an empty BankAccount2 instance with no credentials or balance set.
    • BankAccount

      public BankAccount(String a, String p, float b, SQLite sqlite)
      Constructs a BankAccount2 with the given credentials, balance, and database connection.
      Parameters:
      a - the account number
      p - the account PIN/password
      b - the initial balance in GBP (£)
      sqlite - the SQLite instance used for database operations
  • Method Details

    • withdraw

      public boolean withdraw(float amount)
      Withdraws the given amount from this account. The withdrawal will be rejected if the amount is negative, exceeds the current balance, or would leave the balance below the minimum of £20. On success, the balance is updated in the database and a transaction record is inserted.
      Parameters:
      amount - the amount to withdraw in GBP (£)
      Returns:
      true if the withdrawal was successful, false otherwise
    • withdraw_transferred

      public boolean withdraw_transferred(String accountNumber_receiver, float amount)
      Debits the given amount from this account as part of an outgoing transfer. Applies the same minimum balance and validation rules as withdraw(float). On success, the balance is updated in the database and a transaction record is inserted referencing the receiver's account number.
      Parameters:
      accountNumber_receiver - the account number of the transfer recipient, used in the transaction record
      amount - the amount to debit in GBP (£)
      Returns:
      true if the debit was successful, false otherwise
    • deposit

      public boolean deposit(float amount)
      Deposits the given amount into this account. The deposit will be rejected if the amount is negative. On success, the balance is updated in the database and a transaction record is inserted.
      Parameters:
      amount - the amount to deposit in GBP (£)
      Returns:
      true if the deposit was successful, false if the amount is negative
    • deposit_transferred

      public boolean deposit_transferred(String accountNumber_receiver, float amount)
      Credits the given amount to a receiver's account as part of an incoming transfer. This method does not modify the current account's balance — it updates the receiver's balance directly in the database and inserts a transaction record for the receiver referencing this account number.
      Parameters:
      accountNumber_receiver - the account number to credit
      amount - the amount to credit in GBP (£)
      Returns:
      true if the credit was successful, false if the amount is negative
    • getAccPasswd

      public String getAccPasswd()
      Returns the PIN/password associated with this account.
      Returns:
      the account PIN as a string
    • setAccPasswd

      public void setAccPasswd(String passwd)
      Updates the in memory PIN/password for this account. This does not persist to the database — use SQLite.updatePin(String, String) for database persistence.
      Parameters:
      passwd - the new PIN string to set
    • getBalance

      public float getBalance()
      Returns the current in memory balance for this account.
      Returns:
      the current balance in GBP (£)