Package entity
Class AbstractAccount
java.lang.Object
entity.AbstractAccount
- Direct Known Subclasses:
SavingsAccount
Represents an abstract bank account with basic operations like deposit and withdrawal.
Serves as a base class for specific account types like
SavingsAccount
.- Author:
- TAMIL MUGHILAN
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
protected String
protected BigDecimal
protected int
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractAccount
(int accountNo, int customerId, BigDecimal balance, String accountType) Constructs an AbstractAccount. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canWithdraw
(BigDecimal amount) Checks if a withdrawal of the given amount is allowed.void
deposit
(BigDecimal amount) Deposits the given amount to the account.int
Gets the account number.Gets the account type.Gets the account balance.abstract int
Gets the branch ID where the account is held.int
Gets the customer ID.boolean
Validates the account details.void
setBalance
(BigDecimal balance) Sets the account balance.boolean
withdraw
(BigDecimal amount) Attempts to withdraw the given amount from the account.
-
Field Details
-
accountNo
protected int accountNo -
customerId
protected int customerId -
balance
-
accountType
-
-
Constructor Details
-
AbstractAccount
Constructs an AbstractAccount.- Parameters:
accountNo
- account numbercustomerId
- customer IDbalance
- initial balanceaccountType
- type of account (e.g., "Savings")
-
-
Method Details
-
getBranchId
public abstract int getBranchId()Gets the branch ID where the account is held.- Returns:
- the branch ID
-
canWithdraw
Checks if a withdrawal of the given amount is allowed.- Parameters:
amount
- amount to withdraw- Returns:
true
if withdrawal is allowed;false
otherwise
-
withdraw
Attempts to withdraw the given amount from the account.- Parameters:
amount
- amount to withdraw- Returns:
true
if withdrawal successful;false
otherwise
-
deposit
Deposits the given amount to the account.- Parameters:
amount
- amount to deposit
-
isValidAccount
public boolean isValidAccount()Validates the account details.- Returns:
true
if the account is valid;false
otherwise
-
getAccountNo
public int getAccountNo()Gets the account number.- Returns:
- the account number
-
getCustomerId
public int getCustomerId()Gets the customer ID.- Returns:
- the customer ID
-
getBalance
Gets the account balance.- Returns:
- the current balance
-
getAccountType
Gets the account type.- Returns:
- the account type
-
setBalance
Sets the account balance.- Parameters:
balance
- the new balance
-