Skip to content
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
Binary file added class-diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
| Class | Attribute | Method | Scenario | Output |
|----------------|--------------------------|-------------------------|----------------|-------------------|
| Account | List<Transaction> ledger | getLedger() | | List<Transaction> |
| | String id | deposit(int arg) | | newBalance |
| | float balance | withdraw(int arg) | arg <= balance | newBalance |
| | | | arg > balance | |
| | | getBalance() | | balance |
| | | getTransactionHistory() | | String history |
| SavingAccount | | | | |
| CurrentAccount | | | | |
| | | | | |
| Transaction | float deltaBalance | getDeltaBalance() | | deltaBalance |
| | LocalDateTime timeStamp | getTimeStamp() | | timestamp |
Extension:

| Class | Attribute | Method | Scenario | Output |
|----------------|--------------------------|-------------------------------|----------------|--------------------|
| Account | List<Transaction> ledger | getLedger() | | List<Transaction> |
| | String id | deposit(int arg) | | newBalance |
| | float balance | withdraw(int arg) | arg <= balance | newBalance |
| | float overdraft | | arg > balance | |
| | | getBalance() | | balance |
| | | getTransactionHistory() | | String history |
| | | getBalanceFromLedger() | | float balance |
| | | | | |
| SavingAccount | | | | |
| CurrentAccount | | | | |
| | | | | |
| Transaction | float deltaBalance | getDeltaBalance() | | deltaBalance |
| | LocalDateTime timeStamp | getTimeStamp() | | timestamp |
| Branch | List<Account> accounts | getAccounts() | | List<Account> accs |
| | List<Request> request | getRequests() | | List<Request> reqs |
| | | acceptRequest(Request) | | void |
| | | denyRequest(Request) | | void |
| | | createRequest(Account, float) | | void |
| | | addAccount(Account) | | void |
| Request | Account acc | | | |
| | float overdraft | | | |




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

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class Account {
List<Transaction> ledger;
String id;
float balance;

public Account(List<Transaction> ledger, String id, float balance){
this.ledger = ledger;
this. id = id;
this.balance = balance;
}


public String getTransactionHistory(){
List<Transaction> transactions = new ArrayList<>(ledger); //Clone list to not affect attribute



List<String> rows = new ArrayList<>();

float balance = 0;
for(Transaction tr : transactions){
balance += tr.getDeltaBalance();
StringBuilder sb = new StringBuilder();
String dateStr = tr.getTimeStamp().format(DateTimeFormatter.ofPattern("dd/MM/uuuu"));
sb.append(String.format("%-11s||", dateStr));
if(tr.getDeltaBalance()>0){
sb.append(String.format(" %-8.2f||", tr.getDeltaBalance()));
sb.append(String.format(" %-7s||" ,""));
} else {
sb.append(String.format(" %-8s||" ,""));
sb.append(String.format(" %-7.2f||", -tr.getDeltaBalance()));
}
sb.append(String.format(" %.2f", balance));
sb.append("\n");
rows.add(sb.toString());
}
rows.add("date || credit || debit || balance\n");
String ret = rows.reversed().stream().reduce("", ( (acc,curr) -> acc+curr));
return ret;
}

public float deposit(float val){
this.setBalance(this.getBalance()+val);

this.addLedgerEntry(val);

return this.getBalance();
}

public float withdraw(float amount) throws InsufficientFundsException{
if(amount > this.getBalance()){
throw new InsufficientFundsException();
} else {
this.setBalance(this.getBalance()-amount);

this.addLedgerEntry(-amount);

return this.getBalance();
}

}

private void addLedgerEntry(float val){
Transaction transaction = new Transaction(val, LocalDate.now());
ledger.add(transaction);
}

public List<Transaction> getLedger() {
return ledger;
}

public void setLedger(List<Transaction> ledger) {
this.ledger = ledger;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public float getBalance() {
return balance;
}

public void setBalance(float balance) {
this.balance = balance;
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/booleanuk/core/CurrentAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.booleanuk.core;

import java.util.List;

public class CurrentAccount extends Account{
public CurrentAccount(List<Transaction> ledger, String id, float balance){
super(ledger, id, balance);
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/booleanuk/core/InsufficientFundsException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.booleanuk.core;

public class InsufficientFundsException extends Exception{
public InsufficientFundsException(String message){
super(message);
}

public InsufficientFundsException(){
super();
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/booleanuk/core/SavingsAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.booleanuk.core;

import java.util.List;

public class SavingsAccount extends Account{
public SavingsAccount(List<Transaction> ledger, String id, float balance){
super(ledger, id, balance);
}
}
30 changes: 30 additions & 0 deletions src/main/java/com/booleanuk/core/Transaction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.booleanuk.core;

import java.time.LocalDate;
import java.time.LocalDateTime;

public class Transaction {
private float deltaBalance;
private LocalDate timeStamp;

public Transaction(float deltaBalance ,LocalDate timeStamp){
this.deltaBalance = deltaBalance;
this.timeStamp = timeStamp;
}

public float getDeltaBalance() {
return deltaBalance;
}

public LocalDate getTimeStamp() {
return timeStamp;
}

public void setDeltaBalance(float deltaBalance) {
this.deltaBalance = deltaBalance;
}

public void setTimeStamp(LocalDate timeStamp) {
this.timeStamp = timeStamp;
}
}
Empty file.
117 changes: 117 additions & 0 deletions src/main/java/com/booleanuk/extension/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.booleanuk.extension;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class Account {
List<Transaction> ledger;
String id;
float balance;
float overdraft;



public Account(List<Transaction> ledger, String id, float balance){
this.ledger = ledger;
this. id = id;
this.balance = balance;
this.overdraft = 0;
}

public float getBalanceFromLedger(){
float acc = 0;
for(Transaction curr : ledger){
acc += curr.getDeltaBalance();
}
return acc;
}

public String getTransactionHistory(){
List<Transaction> transactions = new ArrayList<>(ledger); //Clone list to not affect attribute



List<String> rows = new ArrayList<>();

float balance = 0;
for(Transaction tr : transactions){
balance += tr.getDeltaBalance();
StringBuilder sb = new StringBuilder();
String dateStr = tr.getTimeStamp().format(DateTimeFormatter.ofPattern("dd/MM/uuuu"));
sb.append(String.format("%-11s||", dateStr));
if(tr.getDeltaBalance()>0){
sb.append(String.format(" %-8.2f||", tr.getDeltaBalance()));
sb.append(String.format(" %-7s||" ,""));
} else {
sb.append(String.format(" %-8s||" ,""));
sb.append(String.format(" %-7.2f||", -tr.getDeltaBalance()));
}
sb.append(String.format(" %.2f", balance));
sb.append("\n");
rows.add(sb.toString());
}
rows.add("date || credit || debit || balance\n");
String ret = rows.reversed().stream().reduce("", ( (acc,curr) -> acc+curr));
return ret;
}

public float deposit(float val){
this.setBalance(this.getBalance()+val);

this.addLedgerEntry(val);

return this.getBalance();
}

public float getOverdraft() {
return overdraft;
}

public void setOverdraft(float overdraft) {
this.overdraft = overdraft;
}

public float withdraw(float amount) throws InsufficientFundsException {
if(amount > this.getBalance()+overdraft){
throw new InsufficientFundsException();
} else {
this.setBalance(this.getBalance()-amount);

this.addLedgerEntry(-amount);

return this.getBalance();
}

}

private void addLedgerEntry(float val){
Transaction transaction = new Transaction(val, LocalDate.now());
ledger.add(transaction);
}

public List<Transaction> getLedger() {
return ledger;
}

public void setLedger(List<Transaction> ledger) {
this.ledger = ledger;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public float getBalance() {
return balance;
}

public void setBalance(float balance) {
this.balance = balance;
}
}
41 changes: 41 additions & 0 deletions src/main/java/com/booleanuk/extension/Branch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.booleanuk.extension;

import java.util.List;

public class Branch {
private List<Account> accounts;
private List<Request> requests;

public Branch(List<Account> accounts, List<Request> requests){

this.accounts = accounts;
this.requests = requests;
}

public void createRequest(Account acc, float overdraft){
Request req = new Request(acc, overdraft);
this.getRequests().add(req);
}

public void acceptRequest(Request req){
req.getAcc().setOverdraft(req.getOverdraft());
req.getAcc().getOverdraft();
requests.remove(req);
}

public void denyRequest(Request req){
requests.remove(req);
}

public List<Account> getAccounts() {
return accounts;
}

public void addAccount(Account acc){
this.accounts.add(acc);
}

public List<Request> getRequests() {
return requests;
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/booleanuk/extension/CurrentAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.booleanuk.extension;

import java.util.List;

public class CurrentAccount extends Account {
public CurrentAccount(List<Transaction> ledger, String id, float balance){
super(ledger, id, balance);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.booleanuk.extension;

public class InsufficientFundsException extends Exception{
public InsufficientFundsException(String message){
super(message);
}

public InsufficientFundsException(){
super();
}
}
Loading
Loading