Skip to content
Closed
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
36 changes: 36 additions & 0 deletions domainModel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

| Classes | variables | Methods | Scenario | Outputs |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ | -------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| BankAccount | String accountName, Branch branch, <br>List<Map.Entry<LocalDate, <br>Float>> transactions | BankAccount(String accountName,<br>Branch branch) | if all is valid | creates account with no transactions and<br>registers the account to the given branch |
| | | | if branch is null | creates account but does not register to branch |
| | | withdraw(float amount) | if amount < 0 | returns not a valid transaction |
| | | | if ballance is < amount<br>and notallowToOverdraft | returns not enough balance |
| | | | otherwise | add transaction of withdraw |
| | | deposit(float amount) | if amount <= 0 | returns not a valid transaction |
| | | | otherwise | add deposit to transactions |
| | | getSatementsToSTring | | prints out nice looking statement data and history |
| | | requestOverdraft(Bankaccount account) | | request overdraft at given branch and returns value |
| | | getBalance() | | call getbalance(float transaction count) with negative value and returns value |
| | | getBalance(float transaction count) | transaction count < 0 | gives the full transaction hisory |
| | | | otherwise | gives transaction history till the given transaction count |
| | | | | |
| CheckingAccount | | super() | | extends BankAccount |
| SavingsAccount | | super() | | extends BankAccount |
| | | | | |
| Branch | String branchLocation,<br>String managerAccessKey,<br>List/</BankAccount/> accounts,<br>List/</BankAccount/> requestedOverdraft,<br>Lis/</BankAccount/> approvedOverdraft, | Branch(STring branchLocation,<br>String fmanagerAccessKey) | | creates branch object with empty lists |
| | | addAccount | if account is already in accountsList | returns account is already part of branch |
| | | | if not | adds account to the branch |
| | | requestOverdraft(BAnkAccount) | if account is not part of branch | returns bank is not part of branch |
| | | | if account already requested overdraft | returns account already requested overdraft |
| | | | if account already is allowed to overdraft | returns account is allready approved for overdraft |
| | | | otherwise | adds account to list of requested overdraft<br>and returns overdraft has been approved |
| | | processOverdraft(BankAccount account, String accessKey, boolean accepts) | if accessKey is not the one of the manager | returns no authority to process overdrafts |
| | | | if account is not part of this branch | returns account is not part of this branch |
| | | | if accepts is false | removes account from requested list and returns overdraft was rejected |
| | | | if account did not request overdraft | returns no overdraft was requested |
| | | | otherwise | removes account from requested list and adds it tto the approved list and returns overdraft was approved |
| | | wasjapprovedOverdraft(bankaccount account) | | returns if bankaccount is in overdraft approved list |
| OsakaBranch | | super() | | |
| tokyoBranch | | super() | | |


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

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public abstract class BankAccount {

private final String accountName;
private final Branch branch;
private List<Map.Entry<LocalDate, Float>> transactions;

public BankAccount(String accountName, Branch branch) {
this.accountName = accountName;

this.transactions = new ArrayList<>();
this.branch = branch;
if (branch != null)
branch.addAccount(this);
}

public String withdraw(float amount) {
boolean overdraftAllowed = branch.wasApprovedOverdraft(this);

if (amount <= 0)
return "Not a valid transaction";

if (getBalance() < amount && !overdraftAllowed)
return "Not enough balance";


transactions.add(Map.entry(LocalDate.now(), - amount));
return "Withdraw completed";
}

public String deposit(float amount) {
if (amount <= 0)
return "Not a valid transaction";

transactions.add(Map.entry(LocalDate.now(),amount));
return "Amount successfully deposited";
}

public List<Map.Entry<LocalDate, Float>> getStatements() {
return transactions;
}

public String getStatementsToString() {
StringBuilder sb = new StringBuilder();
sb.append("\ndate \t\t | | transactions \t\t | | balance\n");
for (int i = 0; i < transactions.size(); i++) {
var transaction = transactions.get(i);
sb.append(transaction.getKey() +
"\t\t | | " +
transaction.getValue() +
"\t\t | | " +
getBalance(i +1)

+ "\n");

}
return sb.toString();
}

public String requestOverdraft() {
return branch.requestOverdraft(this);
}

public float getBalance() {
return getBalance(-1);
}

public float getBalance(int transactionCount) {

if (transactionCount < 0) {
transactionCount = transactions.size();
}
float balance = 0;
for (int i = 0; i < transactionCount; i++) {
var transaction = transactions.get(i);
balance += transaction.getValue();
}
return balance;
}

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

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

public abstract class Branch {

private String branchLocation;
private String managerAccessKey;
private List<BankAccount> accounts;
private List<BankAccount> requestedOverdraft;
private List<BankAccount> approvedOverdraft;

Branch(String branchLocation, String managerAccessKey1) {
this.branchLocation = branchLocation;
this.managerAccessKey = managerAccessKey1;
this.accounts = new ArrayList<>();
this.requestedOverdraft = new ArrayList<>();
this.approvedOverdraft = new ArrayList<>();
}

public String addAccount(BankAccount account) {
if (accounts.contains(account))
return "Account already part of this branch";

accounts.add(account);
return "Account successfully registered at this branch";
}

public String requestOverdraft(BankAccount account) {
if (!accounts.contains(account))
return "Not part of this branch";

if(requestedOverdraft.contains(account))
return "Already requested overdraft";

if (approvedOverdraft.contains(account))
return "Overdraft already approved";

requestedOverdraft.add(account);
return "Overdraft has been requested";
}

public String processOverdraft(BankAccount account, String accessKey, Boolean approve) {
if (!managerAccessKey.equals(accessKey))
return "No authority to approve overdrafts";

if (!accounts.contains(account))
return "Not part of this branch";


if(requestedOverdraft.contains(account) && approve) {
requestedOverdraft.remove(account);
approvedOverdraft.add(account);
return "Overdraft approved";
}

if (!approve)
return "Overdraft was rejected";

return "No overdraft was requested";
}

public boolean wasApprovedOverdraft(BankAccount account) {
return approvedOverdraft.contains(account);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/CheckingAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class CheckingAccount extends BankAccount{
public CheckingAccount(String accountName, Branch branch) {
super(accountName, branch);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/OsakaBranch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class OsakaBranch extends Branch{
public OsakaBranch() {
super("大阪", "42");
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/SavingsAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class SavingsAccount extends BankAccount{
public SavingsAccount(String accountName, Branch branch) {
super(accountName, branch);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/TokyoBranch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class TokyoBranch extends Branch{
public TokyoBranch() {
super("東京", "454");
}
}
Loading
Loading