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

Refactored Code & Implemented More Features - Nkosilathi #334

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ instructions
* There are several deliberate design, code quality and test issues that should be identified and resolved.
* Below is a list of the current features supported by the application; as well as some additional features that have been requested by the business owner.
* In order to work on this take a fork into your own GitHub area; make whatever changes you feel are necessary and when you are satisfied submit back via a pull request. See details on GitHub's [Fork & Pull](https://help.github.com/articles/using-pull-requests) model
* Be sure to put your name in the pull request comment so your work can be easily identied.
* Be sure to put your name in the pull request comment so your work can be easily identified.
* The project uses maven to resolve dependencies however if you want to avoid maven configuration the only external JAR that's required is junit-4.11.
* Refactor and add features (from the below list) as you see fit; there is no need to add all the features in order to "complete" the exercise. Keep in mind that code quality is the critical measure and there should be an obvious focus on testing.
* You'll notice there is no database or UI; these are not needed - the exercise deliberately avoids these requirements.
Expand Down Expand Up @@ -39,4 +39,4 @@ A dummy application for a bank; should provide various functions of a retail ban

* A customer can transfer between their accounts
* Change **Maxi-Savings accounts** to have an interest rate of 5% assuming no withdrawals in the past 10 days otherwise 0.1%
* Interest rates should accrue and compound daily (incl. weekends), rates above are per-annum
* Interest rates should accrue and compound daily (incl. weekends), rates above are per-annum
73 changes: 0 additions & 73 deletions src/main/java/com/abc/Account.java
Original file line number Diff line number Diff line change
@@ -1,73 +0,0 @@
package com.abc;

import java.util.ArrayList;
import java.util.List;

public class Account {

public static final int CHECKING = 0;
public static final int SAVINGS = 1;
public static final int MAXI_SAVINGS = 2;

private final int accountType;
public List<Transaction> transactions;

public Account(int accountType) {
this.accountType = accountType;
this.transactions = new ArrayList<Transaction>();
}

public void deposit(double amount) {
if (amount <= 0) {
throw new IllegalArgumentException("amount must be greater than zero");
} else {
transactions.add(new Transaction(amount));
}
}

public void withdraw(double amount) {
if (amount <= 0) {
throw new IllegalArgumentException("amount must be greater than zero");
} else {
transactions.add(new Transaction(-amount));
}
}

public double interestEarned() {
double amount = sumTransactions();
switch(accountType){
case SAVINGS:
if (amount <= 1000)
return amount * 0.001;
else
return 1 + (amount-1000) * 0.002;
// case SUPER_SAVINGS:
// if (amount <= 4000)
// return 20;
case MAXI_SAVINGS:
if (amount <= 1000)
return amount * 0.02;
if (amount <= 2000)
return 20 + (amount-1000) * 0.05;
return 70 + (amount-2000) * 0.1;
default:
return amount * 0.001;
}
}

public double sumTransactions() {
return checkIfTransactionsExist(true);
}

private double checkIfTransactionsExist(boolean checkAll) {
double amount = 0.0;
for (Transaction t: transactions)
amount += t.amount;
return amount;
}

public int getAccountType() {
return accountType;
}

}
12 changes: 12 additions & 0 deletions src/main/java/com/abc/AccountTypes/CheckingAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.abc.AccountTypes;

import com.abc.MainClasses.Account;
import com.abc.MainClasses.AccountType;

//Subclass of Account
public class CheckingAccount extends Account {
public CheckingAccount() {
//Call constructor of Account with appropriate parameter
super(AccountType.CHECKING);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/abc/AccountTypes/MaxiSavingsAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.abc.AccountTypes;

import com.abc.MainClasses.Account;
import com.abc.MainClasses.AccountType;

//Subclass of Account
public class MaxiSavingsAccount extends Account {
public MaxiSavingsAccount() {
//Call constructor of Account with appropriate parameter
super(AccountType.MAXI_SAVINGS);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/abc/AccountTypes/SavingsAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.abc.AccountTypes;

import com.abc.MainClasses.Account;
import com.abc.MainClasses.AccountType;

//Subclass of Account
public class SavingsAccount extends Account {
public SavingsAccount() {
//Call constructor of Account with appropriate parameter
super(AccountType.SAVINGS);
}
}
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.

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

import com.abc.MainClasses.AccountType;
//Interface for Account class
public interface AccountInterface {
public void deposit(double amount);

public void withdraw(double amount);

public double interestEarned();

public double sumTransactions();

public AccountType getAccountType();
}
16 changes: 16 additions & 0 deletions src/main/java/com/abc/Interfaces/BankInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.abc.Interfaces;

import com.abc.MainClasses.Customer;

//Interface for Bank class
public interface BankInterface {
public void addCustomer(Customer customer);

public String customerSummary();

public double totalInterestPaid();

public String getFirstCustomer();

public String getLastCustomer();
}
23 changes: 23 additions & 0 deletions src/main/java/com/abc/Interfaces/CustomerInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.abc.Interfaces;

import com.abc.MainClasses.Account;
import com.abc.MainClasses.Customer;

//Interface for Customer class
public interface CustomerInterface {
public String getName();

public Customer openAccount(Account account);

public int getNumberOfAccounts();

public double totalInterestEarned();

public String[] getStatement();

public String statementForAccount(Account account);

public double[] transferFunds(double amount, Account fromAccount, Account toAccount) throws Exception;

public String toDollars(double amount);
}
7 changes: 7 additions & 0 deletions src/main/java/com/abc/Interfaces/DateProviderInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.abc.Interfaces;
import java.util.Date;

//Interface for DateProvider class
public interface DateProviderInterface {
public Date now();
}
5 changes: 5 additions & 0 deletions src/main/java/com/abc/Interfaces/TransactionInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.abc.Interfaces;

//Interface for Transaction class
public interface TransactionInterface {
}
Loading