Skip to content

feat: implement bank account system with audit logging to BankATM #526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.codedifferently.lesson17.bank;


import java.util.ArrayList;

public class AuditLog {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a bad implementation, good work. You might be interested in a library called Log4j that could be useful to you as well, but this is good enough for your homework.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored AuditLog class to Implement Log4j logic instead of custom implementation.

private List<String> logEntries = new ArrayList<>();

public void log (String message) {
logEntries.add(message);
System.out.println(message);

}

public List<String> getEntries() {
return logEntries;
}

public void clear() {
logEntries.clear();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.codedifferently.lesson17.bank;
/* We want to support a Savings Account that works just like CheckinAccount,
* But will not allow you to write checks aainst the account.
*
* We want the BankAtm class to support the concept of a Business Checking Account
* A business acount will require that at least ne of the owning accoutns is a business account.
*
*/

public abstract class BankAccount {
protected String accountNumber;
protected double balance;

public abstract void deposit(double amount, String method);
public abstract void withdraw(double amount);

public double getBalance() {
return balance;
}
public String getAccountNumber() {
return accountNumber;
}

//Follows LSP
public interface depositable {
void deposit(double amount, String method);
}
public interface withdrawable {
void withdraw(double amount);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.codedifferently.lesson17.bank;

import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;

/** Represents a bank ATM. */
public class BankAtm {

private final Map<UUID, Customer> customerById = new HashMap<>();
private final Map<String, CheckingAccount> accountByNumber = new HashMap<>();

private final AuditLog auditLog = new AuditLog();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Violates the D in SOLID, no?

/**
* Adds a checking account to the bank.
*
Expand Down Expand Up @@ -48,6 +49,7 @@ public Set<CheckingAccount> findAccountsByCustomerId(UUID customerId) {
public void depositFunds(String accountNumber, double amount) {
CheckingAccount account = getAccountOrThrow(accountNumber);
account.deposit(amount);
auditLog.log("Deposited " + amount + " into account " + accountNumber);
}

/**
Expand All @@ -58,8 +60,11 @@ public void depositFunds(String accountNumber, double amount) {
*/
public void depositFunds(String accountNumber, Check check) {
CheckingAccount account = getAccountOrThrow(accountNumber);

check.depositFunds(account);
}
auditLog.log("Deposited check into account " + accountNumber);

}

/**
* Withdraws funds from an account.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//Only Allows Deposits when accessing Atm on your Savings Account

public class SavingsAccount extends BankAccount {

@Override
public void deposit(double amount, String method) {
if("check".equalsIgnoreCase(method)) {
throw new UnsupportedOperationException("Deposit not allowed");
}

this.balance += amount;
}

@Override
public void withdraw(double amount) {
throw new IllegalArgumentException("Insufficient funds");
}
}
Loading