Package service
Class AccountService
java.lang.Object
service.AccountService
Service class for managing bank account operations.
Handles account creation, transactions, and joint account operations.
- Author:
- TAMIL MUGHILAN
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAccountService
(DataStorage dataStorage) Creates a new AccountService with the specified data storage based on user's choice. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addCustomerToExistingAccount
(int customerId, int accountNo) Adds a customer to an existing account as joint holder.int
createJointSavingsAccount
(String customerIdsStr, BigDecimal initialBalance, int branchId) Creates a joint savings account from comma separated customer IDs.int
createJointSavingsAccount
(List<Integer> customerIds, BigDecimal initialBalance, int branchId) Creates a joint savings account for multiple customers.int
createSavingsAccount
(int customerId, BigDecimal initialBalance, int branchID) Creates a new savings account for a customer.boolean
deleteAccount
(int accountNo) Deletes an account by account number.getAccount
(int accountNo) Retrieves an account by account number.getAccountHolders
(int accountNo) Gets all customers who are holders of an account.getAccountsByBranch
(int branchId) Gets all accounts for a specific branch.getAccountsByCustomer
(int customerId) Gets all accounts for a specific customer.getTransactionHistory
(int accountNo) Gets transaction history for an account (default 50 records).getTransactionHistory
(int accountNo, int limit) Gets transaction history for an account with specified limit.boolean
performDeposit
(int accountNo, BigDecimal amount) boolean
performDeposit
(int accountNo, BigDecimal amount, Integer userId, TransactionLog.UserType userType, String description) Performs a deposit with transaction logging.boolean
performWithdrawal
(int accountNo, BigDecimal amount) boolean
performWithdrawal
(int accountNo, BigDecimal amount, Integer userId, TransactionLog.UserType userType, String description) Performs a withdrawal with transaction logging.boolean
removeCustomerFromAccount
(int customerId, int accountNo) Removes a customer from a joint account.void
updateAccount
(SavingsAccount account) Updates an existing account.
-
Field Details
-
dataStorage
-
-
Constructor Details
-
AccountService
Creates a new AccountService with the specified data storage based on user's choice.- Parameters:
dataStorage
- the data storage implementation to use
-
-
Method Details
-
createSavingsAccount
Creates a new savings account for a customer.- Parameters:
customerId
- the customer IDinitialBalance
- the initial balance (minimum Rs.100)branchID
- the branch ID- Returns:
- the new account number
- Throws:
IllegalArgumentException
- if parameters are invalid
-
getAccount
Retrieves an account by account number.- Parameters:
accountNo
- the account number- Returns:
- the savings account or null if not found
-
updateAccount
Updates an existing account.- Parameters:
account
- the account to update
-
deleteAccount
public boolean deleteAccount(int accountNo) Deletes an account by account number.- Parameters:
accountNo
- the account number to delete- Returns:
- true if deletion was successful, false otherwise
-
getAccountsByBranch
Gets all accounts for a specific branch.- Parameters:
branchId
- the branch ID- Returns:
- list of accounts in the branch
-
getAccountsByCustomer
Gets all accounts for a specific customer.- Parameters:
customerId
- the customer ID- Returns:
- list of customer's accounts
-
performWithdrawal
-
performDeposit
-
performWithdrawal
public boolean performWithdrawal(int accountNo, BigDecimal amount, Integer userId, TransactionLog.UserType userType, String description) Performs a withdrawal with transaction logging.- Parameters:
accountNo
- the account numberamount
- the amount to withdrawuserId
- the user performing the transactionuserType
- the type of user (CUSTOMER, EMPLOYEE, MANAGER)description
- description of the transaction- Returns:
- true if withdrawal was successful, false otherwise
-
performDeposit
public boolean performDeposit(int accountNo, BigDecimal amount, Integer userId, TransactionLog.UserType userType, String description) Performs a deposit with transaction logging.- Parameters:
accountNo
- the account numberamount
- the amount to deposituserId
- the user performing the transactionuserType
- the type of user (CUSTOMER, EMPLOYEE, MANAGER)description
- description of the transaction- Returns:
- true if deposit was successful, false otherwise
-
createJointSavingsAccount
public int createJointSavingsAccount(List<Integer> customerIds, BigDecimal initialBalance, int branchId) Creates a joint savings account for multiple customers.- Parameters:
customerIds
- list of customer IDs for the joint accountinitialBalance
- the initial balance (minimum Rs.100)branchId
- the branch ID- Returns:
- the new account number
- Throws:
IllegalArgumentException
- if parameters are invalid
-
createJointSavingsAccount
public int createJointSavingsAccount(String customerIdsStr, BigDecimal initialBalance, int branchId) Creates a joint savings account from comma separated customer IDs.- Parameters:
customerIdsStr
- comma-separated customer IDs (e.g., "1,2,3")initialBalance
- the initial balance (minimum Rs.100)branchId
- the branch ID- Returns:
- the new account number
- Throws:
IllegalArgumentException
- if parameters are invalid
-
addCustomerToExistingAccount
public boolean addCustomerToExistingAccount(int customerId, int accountNo) Adds a customer to an existing account as joint holder.- Parameters:
customerId
- the customer ID to addaccountNo
- the account number- Returns:
- true if customer was added successfully, false otherwise
- Throws:
IllegalArgumentException
- if customer or account doesn't exist
-
removeCustomerFromAccount
public boolean removeCustomerFromAccount(int customerId, int accountNo) Removes a customer from a joint account.- Parameters:
customerId
- the customer ID to removeaccountNo
- the account number- Returns:
- true if customer was removed successfully, false otherwise
- Throws:
IllegalStateException
- if trying to remove the last customer
-
getAccountHolders
Gets all customers who are holders of an account.- Parameters:
accountNo
- the account number- Returns:
- list of customers who hold the account
-
getTransactionHistory
Gets transaction history for an account (default 50 records).- Parameters:
accountNo
- the account number- Returns:
- list of transaction logs
-
getTransactionHistory
Gets transaction history for an account with specified limit.- Parameters:
accountNo
- the account numberlimit
- maximum number of records to retrieve- Returns:
- list of transaction logs
-