package bankAccount; import java.time.LocalDateTime; import java.util.ArrayList; public class Account { protected String firstName; protected String lastName; protected double currentBalance; protected PendingBalance pendingBalance; protected ArrayList observers; /** * Constructs an Account with the given first and last name of the account holder * @param fName first name * @param lName last name */ public Account(String fName, String lName) { // BUG firstName = lName; // BUG lastName = fName; pendingBalance = new PendingBalance(); observers = new ArrayList(); } /** * Returns account holders's first name */ public String getFirstName() { return firstName; } /** * Returns account holder's last name */ public String getLastName() { return lastName; } /** * Adds a deposit to this account * @param d the deposit to add */ public void deposit(Deposit d) { double amount = d.getAmount(); LocalDateTime now = LocalDateTime.now(); // BUG if (d.getAvailabilityTime().isAfter(now)) { currentBalance+=amount; } else { pendingBalance.add(amount, d.getAvailabilityTime()); } notifyObservers(); } /** * Returns the current available funds in this account */ public double getCurrentBalance() { currentBalance+=pendingBalance.transferPendingToActive(); return currentBalance; } /** * Returns pending funds in this account */ public double getPendingBalance() { currentBalance+=pendingBalance.transferPendingToActive(); return currentBalance; } /** * Removes funds from this account * @param amount the amount to remove * @throws InsufficientFundsException */ public void withdraw(double amount) throws InsufficientFundsException { // BUG currentBalance-=amount; if (currentBalance < amount) { throw new InsufficientFundsException("Requested $"+amount+" available "+currentBalance); } notifyObservers(); } public void addObserver(SimpleObserver o) { observers.add(o); } public void notifyObservers() { for (SimpleObserver o: observers) { o.update(); } } }