java.lang.Object
com.atmbanksimulator.BankAccount
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
ConstructorsConstructorDescriptionDefault constructor.BankAccount(String a, String p, float b, SQLite sqlite) Constructs aBankAccount2with the given credentials, balance, and database connection. -
Method Summary
Modifier and TypeMethodDescriptionbooleandeposit(float amount) Deposits the given amount into this account.booleandeposit_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.floatReturns the current in memory balance for this account.voidsetAccPasswd(String passwd) Updates the in memory PIN/password for this account.booleanwithdraw(float amount) Withdraws the given amount from this account.booleanwithdraw_transferred(String accountNumber_receiver, float amount) Debits the given amount from this account as part of an outgoing transfer.
-
Constructor Details
-
BankAccount
public BankAccount()Default constructor. Creates an emptyBankAccount2instance with no credentials or balance set. -
BankAccount
Constructs aBankAccount2with the given credentials, balance, and database connection.- Parameters:
a- the account numberp- the account PIN/passwordb- the initial balance in GBP (£)sqlite- theSQLiteinstance 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:
trueif the withdrawal was successful,falseotherwise
-
withdraw_transferred
Debits the given amount from this account as part of an outgoing transfer. Applies the same minimum balance and validation rules aswithdraw(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 recordamount- the amount to debit in GBP (£)- Returns:
trueif the debit was successful,falseotherwise
-
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:
trueif the deposit was successful,falseif the amount is negative
-
deposit_transferred
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 creditamount- the amount to credit in GBP (£)- Returns:
trueif the credit was successful,falseif the amount is negative
-
getAccPasswd
Returns the PIN/password associated with this account.- Returns:
- the account PIN as a string
-
setAccPasswd
Updates the in memory PIN/password for this account. This does not persist to the database — useSQLite.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 (£)
-