Skip to content
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

Thomas Sarno Accenture PR #331

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e261fce
updated account with balance, added transaction datestamp
TJSarno Aug 10, 2023
b7c8f06
file restructure, added interest calculations in a seperate helper fu…
TJSarno Aug 11, 2023
2d66511
refactored helper functions
TJSarno Aug 11, 2023
6caa81e
added public wrapper, removed unused code
TJSarno Aug 11, 2023
8bfb980
refactored customer functions, added customer statement builder
TJSarno Aug 11, 2023
da7fd08
refactored customer functions, added statement builder
TJSarno Aug 12, 2023
7c266d6
fixed typos, changed static type in customer, refactored bank
TJSarno Aug 13, 2023
49da5bf
moved all tests to feature folder, created a test runner to run the t…
TJSarno Aug 13, 2023
90e14e2
updated statement builder to include name
TJSarno Aug 13, 2023
489f648
updated statement to have total, added concatenate to have a comparis…
TJSarno Aug 13, 2023
37cb9b6
removed unused testrunner file
TJSarno Aug 13, 2023
fd3c435
removed println
TJSarno Aug 13, 2023
2c7fe76
added deposit tag, refactored customer statement to include transactions
TJSarno Aug 14, 2023
db3dcb6
added comments to statement builder, regex examples in customerTest
TJSarno Aug 14, 2023
31e1b25
updated account test criteria, added account test, removed various un…
TJSarno Aug 14, 2023
cb54ea1
updated test runner, removed unused imports and code in various files
TJSarno Aug 14, 2023
f6686fc
removed unused import
TJSarno Aug 14, 2023
5612b6a
spacing
TJSarno Aug 14, 2023
3c98310
tidied up return of AccountStatements
TJSarno Aug 15, 2023
87bf416
Tidied formatting across all files
TJSarno Aug 17, 2023
34abf12
renamed 'features' to 'tests, updated pathing across files
TJSarno Aug 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.debug.settings.onBuildFailureProceed": true
}
73 changes: 0 additions & 73 deletions src/main/java/com/abc/Account.java

This file was deleted.

46 changes: 0 additions & 46 deletions src/main/java/com/abc/Bank.java

This file was deleted.

78 changes: 0 additions & 78 deletions src/main/java/com/abc/Customer.java

This file was deleted.

18 changes: 0 additions & 18 deletions src/main/java/com/abc/DateProvider.java

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/java/com/abc/Transaction.java

This file was deleted.

126 changes: 126 additions & 0 deletions src/main/java/com/abc/classes/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.abc.classes;

import java.util.ArrayList;
import java.util.List;
import com.abc.helpers.AccountInterests;

public class Account {

public enum AccountType {
CHECKING, SAVINGS, MAXI_SAVINGS, MAXI_SAVINGS_PLUS
}

AccountType accountType;
private List<Transaction> transactions;
private double balance;
private double accruedInterest;

public Account(AccountType account) {
this.accountType = account;
this.balance = 0; // Assuming a new account opens with an empty balance
this.accruedInterest = 0; // Assuming a new account opens with no acrrued interest
this.transactions = new ArrayList<Transaction>();
}

// Getters//
public Account getAccount() {
return this;
}

public AccountType getAccountType() {
return accountType;
}

public List<Transaction> getTransactions() {
return transactions;
}

public Transaction getLatestTransaction() {
Transaction latestTransaction = transactions.get(transactions.size() - 1);
return latestTransaction;
}

public double getBalance() {
return balance;
}

public double getAccruedInterest() {
return accruedInterest;
}

// Transaction Functions//
// Update balance, called everytime a deposit or withdrawal is made
public void updateBalance(double amount) {
balance += amount;
}

// Update the accrued interest, called everytime interest is added to the
// account
public void updateAccuredInterest(double amount) {
accruedInterest += amount;
}

// Private deposit functions wrapped in public try catch functions
private void deposit(double amount) {
if (amount <= 0) {
throw new IllegalArgumentException("Amount must be greater than zero");
} else {
transactions.add(new Transaction(amount, "(IN)"));
updateBalance(amount);
}
}

private void withdraw(double amount) {
if (amount <= 0) {
throw new IllegalArgumentException("Amount must be greater than zero");
} else if (amount > balance) {
throw new IllegalArgumentException("Amount withdrawn must be less than your current balance");

} else {
transactions.add(new Transaction(-amount, "(OUT)"));
updateBalance(-amount);
}
}

public void tryDeposit(double amount) {
try {
// Attempt to make a deposit
deposit(amount);
} catch (IllegalArgumentException e) {
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
}
}

public void tryWithdraw(double amount) {
try {
// Attempt to make a withdrawal
withdraw(amount);
} catch (IllegalArgumentException e) {
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
}
}

// Interest functions//
public void addInterest() {
// Switch case based on what type of account it is, taken to
// AccountInterests.java to handle the logic
switch (accountType) {
case CHECKING:
AccountInterests.calculateInterestChecking(getAccount());
break;
case SAVINGS:
AccountInterests.calculateInterestSavings(getAccount());
break;
case MAXI_SAVINGS:
AccountInterests.calculateInterestMaxiSavings(getAccount());
break;
case MAXI_SAVINGS_PLUS:
AccountInterests.calculateInterestMaxiSavingsPlus(getAccount());
break;
default:
System.out.println("Could not find account with account type: " + accountType);
}
}
}
Loading