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
50 changes: 50 additions & 0 deletions src/main/domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
As a customer,
So I can safely store and use my money,
I want to create a current account.

As a customer,
So I can save for a rainy day,
I want to create a savings account.

As a customer,
So I can keep a record of my finances,
I want to generate bank statements with transaction dates, amounts, and balance at the time of transaction.

As a customer,
So I can use my account,
I want to deposit and withdraw funds.

| Classes | Variables | Method | Scenario | Output |
|------------|-----------------|----------------------------------------------------------------------|--------------------------------------------------|-------------------------------------------------|
| Customer | Account.balance | Account Customer.createAccount(String type) | If type is valid and account created | Account |
| Account | | | if type is invalid | null |
| | | | if account already created | null |
| | | | | |
| | Account.balance | Float Customer.withdrawFunds(Float amount, Account account) | if amount is less than balance | the amount left i account |
| | | | if amount is more than balance | -1.00f |
| | Account.balance | Float Customer.depositFunds(Float amount, Account account) | Parameters are valid | the amount in account |
| | | | parameters are not valid | null |
| | | | | |
| | transactions | String Customer.generateBankStatement(StringType) | if the account has transactions | return the bank statement |
| | | | if no transactions | return " " |
| | | | | |
| | | Float Customer.getBalanceHardWay(String Type) | account has transactions | return the balance |
| | | | if transactions is empty | -1.00f |
| | | | | |
| | branch | boolean Customer.setBranch(String branch) | if place is a place | true |
| | | | if place is " " | false |
| | | | | |
| | | boolean Customer.overdraft(Float amount ) | if amount is more than 200 over bal and approved | false |
| | | | if it is less than 200 over bal | true |
| | | | if the amount is less than bal | false |
| | | | | |
| | | boolean Customer.createRequests(Float amount) | if amount is overdraft and is under 400 | List created and return true |
| | | | if overdraft is over 400 | nothing happens return true |
| | | | if i write something else | |
| | | | | |
| | | boolean Customer.approveRequest( Float request, boolean approved) | if approved is true | hashmap is updated and deleted when set through |
| | | | if approved is false | request is declined and entry is deleted. |
| | | | if request found | false |
| | | | if request not found but approved is true | false |
| | | | | |
| | | | | |
Binary file added src/main/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions src/main/java/com/booleanuk/core/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.booleanuk.core;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Objects;

public abstract class Account {
protected Float balance;
protected ArrayList<Transaction> transactions;
protected ArrayList<Float> requests;




public Account(ArrayList<Transaction> transactions) {
this.balance = 0.00f;
this.transactions = transactions;
this.requests = new ArrayList<Float>();
}

public Float findAmount(Float amount){
for (Float item : requests){
if (Objects.equals(item, amount)) {
return item;
}
}
return -999.40f;
}

public boolean addRequest(Float amount){
requests.add(amount);
return true;
}

public void removeRequest(Float amount){
requests.remove(amount);
}


public Float addAmount(Float amount){
balance+= amount;
transactions.add(new Transaction(LocalDate.now(),amount, balance, "+"));

return balance;
}

public Float getBalance() {
return balance;
}

public Float withdrawAmount(Float amount){
balance-= amount;
transactions.add(new Transaction(LocalDate.now(),amount, balance, "-"));

return balance;
}
public boolean generateBankStatement(){
String statement = " ";
for (Transaction transaction : transactions) {
statement += transaction.getInfo() + "\n";
}
System.out.println(statement);
return true;
}


public Float getBalanceHardWay(){
Float bal = 0.00f;
for (Transaction transaction : transactions) {
if (transaction.getType()){
bal += transaction.getAmount();
}
else {
bal -= transaction.getAmount();

}
}
return bal;
}



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

import java.util.ArrayList;

public class Current extends Account{

public Current(ArrayList<Transaction> transactions) {
super(transactions);
}



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

import java.util.ArrayList;

public class Customer {
Savings savings;
Current current;
enum Branch {
OSLO, BERGEN, HARDANGER
}
Customer.Branch branch;


public Customer() {
this.branch = Branch.BERGEN;
}

public Boolean setBranch(Customer.Branch branch) {
this.branch = branch;
return true;
}
public boolean overdraft(Float amount){
if (amount < current.getBalance()+200){
//må legge til at dette er ekstraordinert`?
current.withdrawAmount(amount);
return true;
}
return false;
}

public boolean createRequests(Float amount){
if (amount < current.getBalance()+400.00f){
//må legge til at dette er ekstraordinert`?

return current.addRequest(amount);

}

return false;
}

public boolean approveRequests(Float requests, boolean approved){
if (current.findAmount(requests) != -999.40f) {
if (approved) {
current.withdrawAmount(requests);
return true;
}
current.removeRequest(requests);
}

return false;
}

//Should I have this as boolean or as object as return? when I tried with a object it did not pass the test.
public boolean createAccount(String type){

if (type.equalsIgnoreCase("SAVINGS")){

savings = new Savings(new ArrayList<Transaction>());
return true;
}
if (type.equalsIgnoreCase("CURRENT")){

current = new Current(new ArrayList<Transaction>());
return true;
}

return false;
}
public Float withdrawFunds(Float amount, String type){
if (type.equalsIgnoreCase("SAVINGS")){
if (amount <= savings.getBalance())
return savings.withdrawAmount(amount);
}
if (type.equalsIgnoreCase("CURRENT")){
if (amount <= current.getBalance())
return current.withdrawAmount(amount);

}
return -1.00f;
}
//it does not work with giving account as a parameter? I need to do it with the variables for customer?
public Float depositFunds(Float amount, String type){

if (type.equalsIgnoreCase("SAVINGS")){
return savings.addAmount(amount);
}
if (type.equalsIgnoreCase("CURRENT")){
return current.addAmount(amount);

}


return -1.00f;
}
//I am not sure how to test it wihout true or false

public boolean generateBankStatement(String type){

if (type.equalsIgnoreCase("SAVINGS")) {

if (savings.transactions.size() > 0){
System.out.println("\n ---- BANK STATEMENT ---- \n\tFor Savings account");

return savings.generateBankStatement();
}
}
if (type.equalsIgnoreCase("CURRENT")){
if (current.transactions.size()>0) {
System.out.println("\n ---- BANK STATEMENT ---- \n\tFor Current account");

return current.generateBankStatement();
}

}

return false;
}
public Float getBalanceHardWay(String type){

if (type.equalsIgnoreCase("SAVINGS")) {

if (savings.transactions.size() > 0){

return savings.getBalanceHardWay();
}
}
if (type.equalsIgnoreCase("CURRENT")){
if (current.transactions.size()>0) {
System.out.println("\n ---- BANK STATEMENT ---- \n\tFor Current account");

return current.getBalanceHardWay();
}

}
return -1.00f;

}
}


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

import java.util.ArrayList;

public class Savings extends Account {

public Savings( ArrayList<Transaction> transactions) {
super(transactions);
}


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

import java.time.LocalDate;
import java.util.Objects;

public class Transaction {
private final LocalDate date;
private final Float amount;
private final Float balance;
private final String type;

public Transaction(LocalDate date, Float amount, Float balance, String type) {
this.date = date;
this.amount = amount;
this.balance = balance;
this.type = type;
}

public String getInfo(){
return "Date: " + date.toString() + "\t Amount: " + type+amount.toString() + "\t balance after " + balance.toString();
}

public Float getAmount() {
return amount;
}

public boolean getType() {
if (Objects.equals(type, "-")){
return false;
}
else if (Objects.equals(type, "+"))
return true;

return false;
}
}
Loading
Loading