Package service

Class AccountService

java.lang.Object
service.AccountService

public class AccountService extends Object
Service class for managing bank account operations. Handles account creation, transactions, and joint account operations.
Author:
TAMIL MUGHILAN
  • Field Details

  • Constructor Details

    • AccountService

      public AccountService(DataStorage dataStorage)
      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

      public int createSavingsAccount(int customerId, BigDecimal initialBalance, int branchID)
      Creates a new savings account for a customer.
      Parameters:
      customerId - the customer ID
      initialBalance - the initial balance (minimum Rs.100)
      branchID - the branch ID
      Returns:
      the new account number
      Throws:
      IllegalArgumentException - if parameters are invalid
    • getAccount

      public SavingsAccount getAccount(int accountNo)
      Retrieves an account by account number.
      Parameters:
      accountNo - the account number
      Returns:
      the savings account or null if not found
    • updateAccount

      public void updateAccount(SavingsAccount account)
      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

      public List<SavingsAccount> getAccountsByBranch(int branchId)
      Gets all accounts for a specific branch.
      Parameters:
      branchId - the branch ID
      Returns:
      list of accounts in the branch
    • getAccountsByCustomer

      public List<SavingsAccount> getAccountsByCustomer(int customerId)
      Gets all accounts for a specific customer.
      Parameters:
      customerId - the customer ID
      Returns:
      list of customer's accounts
    • performWithdrawal

      public boolean performWithdrawal(int accountNo, BigDecimal amount)
    • performDeposit

      public boolean performDeposit(int accountNo, BigDecimal amount)
    • 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 number
      amount - the amount to withdraw
      userId - the user performing the transaction
      userType - 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 number
      amount - the amount to deposit
      userId - the user performing the transaction
      userType - 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 account
      initialBalance - 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 add
      accountNo - 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 remove
      accountNo - the account number
      Returns:
      true if customer was removed successfully, false otherwise
      Throws:
      IllegalStateException - if trying to remove the last customer
    • getAccountHolders

      public List<Customer> getAccountHolders(int accountNo)
      Gets all customers who are holders of an account.
      Parameters:
      accountNo - the account number
      Returns:
      list of customers who hold the account
    • getTransactionHistory

      public List<TransactionLog> getTransactionHistory(int accountNo)
      Gets transaction history for an account (default 50 records).
      Parameters:
      accountNo - the account number
      Returns:
      list of transaction logs
    • getTransactionHistory

      public List<TransactionLog> getTransactionHistory(int accountNo, int limit)
      Gets transaction history for an account with specified limit.
      Parameters:
      accountNo - the account number
      limit - maximum number of records to retrieve
      Returns:
      list of transaction logs