From fd9baf89d0163818978593bd2e9bbc80163ba43c Mon Sep 17 00:00:00 2001 From: Emanuels Zaurins Date: Wed, 13 Aug 2025 10:16:25 +0200 Subject: [PATCH 1/3] Red stage --- src/main/domain-model.md | 34 +++++++ src/main/img.png | Bin 0 -> 19422 bytes src/main/java/com/booleanuk/core/Account.java | 13 +++ src/main/java/com/booleanuk/core/Current.java | 10 ++ .../java/com/booleanuk/core/Customer.java | 18 ++++ src/main/java/com/booleanuk/core/Savings.java | 10 ++ .../java/com/booleanuk/core/Transaction.java | 16 +++ .../java/com/booleanuk/core/coreTest.java | 95 ++++++++++++++++++ 8 files changed, 196 insertions(+) create mode 100644 src/main/domain-model.md create mode 100644 src/main/img.png create mode 100644 src/main/java/com/booleanuk/core/Account.java create mode 100644 src/main/java/com/booleanuk/core/Current.java create mode 100644 src/main/java/com/booleanuk/core/Customer.java create mode 100644 src/main/java/com/booleanuk/core/Savings.java create mode 100644 src/main/java/com/booleanuk/core/Transaction.java create mode 100644 src/test/java/com/booleanuk/core/coreTest.java diff --git a/src/main/domain-model.md b/src/main/domain-model.md new file mode 100644 index 000000000..281604e45 --- /dev/null +++ b/src/main/domain-model.md @@ -0,0 +1,34 @@ +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(Account account) | if the account has transactions | return the bank statement | +| | | | if no transactions | return " " | +| | | | | | +| | | | | | +| | | | | | +| | | | | | +| | | | | | diff --git a/src/main/img.png b/src/main/img.png new file mode 100644 index 0000000000000000000000000000000000000000..7dfb654974ba879fef14303979dea142fbbb807f GIT binary patch literal 19422 zcmeIaWmJ@H-#0pl(qT~|At)-1NJyii5`u~_ATfl1N+}&fC?EXi+Iv6GUeEhwe;U>>=Mn$-{rh}-s$igc1gUP}I>-k-s^6%?bk1{HlIk^}dJc!Z2;_IX$0-s>XALm9y!$p1u|kJ!1xO=ip&Fd%=O?zOde5!_2 zHV@r9k6k}}Xs&5Hd8BU`#l!(E&7+wlKj%n$gKAg9VIvi~>*1oXn2}Aha zv#JYWArtvz4ciStdKe^)6L84?D3+dIjd+Nc%!WW382d%QK2^Xf-s{AgTk6E{jg%67 zE}yYGRtsf}BW{qgP{2-=SNNb0V2OA~RAzpHZ~M7Gv6P#CE$}@9PpG0~{>VxTi#Bmh zEaviGfOsf3Y5f#w)e{GJsSH}A~a`c0V> z+wIhB2$N)kAxAJwD(=Vr@rxgl?b00{^^%_^BN0Qr2_9RUQ#CC)%SDu(Cgkf~4HSEG z-;nrVgTOfTk`rm~Kpf42H+b*ViHXI~iNW;D=7zvkp_< z`-+Hh7AvX2Fx|#HoPy?v7dRiUvc8S6WW;6~(ZC*YdMe(#a8g5GAn1UI$(uDClr3?q zeO{PUbI$3uH;g9q)^5*I6v}TP-U~;o{t$7%=V4e~M_LW#;-fxtNTMV%X~HZidz(G^ zjm~4Aj8I*zgc(IINSg30+#p`XG%lrma{P4X!Y^Zi&F$Aux22_G&T zaeEXcAMr!H_-dQrxdIEdbSEC%(Mg4(>K0n#5z9)Gv+z>F6Id(UwdIRnDMj3lLpLfJ zqQ%3JslBps0tgEWJ?s%bOW?d#6w~cxqhrHWU!L4I(>z)2@CrY&JLEiEeuy&Y2^Pp*>#hrZ7=dr3J(ozhNT8dJ!8aBIl1UvT(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`aNY{-1KXa%MkXo;_f=;TXgm_P;7q9vF3f~8GSI9@99Zzjh{tr{Avyok9-wccV2vY<-ep_JLde;$>eI?Td?4D?f|%!#ADJX@+3X2SIo zu=bb&TV0tc=R;1hESA*Gcfq0dosNItgb4=mdi_6-1W`c6Csd05rJZg z#7|lBLZ6Rt&LKzb`LC)8dtUD&F;40Au5$0$mKhaj!jk~z1wl2MjFNp7A52>U transactions; + + public Account(Float balance, ArrayList transactions) { + this.balance = balance; + this.transactions = transactions; + } +} diff --git a/src/main/java/com/booleanuk/core/Current.java b/src/main/java/com/booleanuk/core/Current.java new file mode 100644 index 000000000..b45a6ea78 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Current.java @@ -0,0 +1,10 @@ +package com.booleanuk.core; + +import java.util.ArrayList; + +public class Current extends Account{ + + public Current(Float balance, ArrayList transactions) { + super(balance, transactions); + } +} diff --git a/src/main/java/com/booleanuk/core/Customer.java b/src/main/java/com/booleanuk/core/Customer.java new file mode 100644 index 000000000..ebebfc0de --- /dev/null +++ b/src/main/java/com/booleanuk/core/Customer.java @@ -0,0 +1,18 @@ +package com.booleanuk.core; + +public class Customer { + + public Boolean createAccount(String type){ + return false; + } + public Float withdrawFunds(Float amount, Account account){ + return 0.00f; + } + public Float depositFunds(Float amount, Account account){ + return 0.00f; + } + public Float generateBankStatement(Account account){ + return 0.00f; + } +} + diff --git a/src/main/java/com/booleanuk/core/Savings.java b/src/main/java/com/booleanuk/core/Savings.java new file mode 100644 index 000000000..d4cd49979 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Savings.java @@ -0,0 +1,10 @@ +package com.booleanuk.core; + +import java.util.ArrayList; + +public class Savings extends Account { + + public Savings(Float balance, ArrayList transactions) { + super(balance, transactions); + } +} diff --git a/src/main/java/com/booleanuk/core/Transaction.java b/src/main/java/com/booleanuk/core/Transaction.java new file mode 100644 index 000000000..86b93aa1d --- /dev/null +++ b/src/main/java/com/booleanuk/core/Transaction.java @@ -0,0 +1,16 @@ +package com.booleanuk.core; + +import java.time.LocalDate; + +public class Transaction { + private LocalDate date; + private Float amount; + private Float balance; + + public Transaction(LocalDate date, Float amount, Float balance) { + this.date = date; + this.amount = amount; + this.balance = balance; + } + +} diff --git a/src/test/java/com/booleanuk/core/coreTest.java b/src/test/java/com/booleanuk/core/coreTest.java new file mode 100644 index 000000000..b4db8203c --- /dev/null +++ b/src/test/java/com/booleanuk/core/coreTest.java @@ -0,0 +1,95 @@ +package com.booleanuk.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; + +public class coreTest { + + @Test + public void createAccountTest(){ + Customer customer = new Customer(); + ArrayList transactions = new ArrayList(); + Current current = new Current(0.00f, transactions ); + Savings savings = new Savings(0.00f, transactions ); + + Assertions.assertEquals(new Current(0.00f, transactions ), customer.createAccount("current")); + + Assertions.assertEquals(new Savings(0.00f, transactions ), customer.createAccount("savings")); + + Assertions.assertEquals(null, customer.createAccount("savngs")); + Assertions.assertEquals(null, customer.createAccount("curngs")); + + } + @Test + public void depositTest(){ + Customer customer = new Customer(); + ArrayList transactions = new ArrayList(); + Current current = new Current(0.00f, transactions ); + Savings savings = new Savings(0.00f, transactions ); + + + Assertions.assertEquals(2500.00f, customer.depositFunds(2500.00f, savings)); + Assertions.assertEquals(5000.00f, customer.depositFunds(2500.00f, savings)); + + Assertions.assertEquals(2500.00f, customer.depositFunds(2500.00f, current)); + Assertions.assertEquals(5000.00f, customer.depositFunds(2500.00f, current)); + + Assertions.assertEquals(7150.00f, customer.depositFunds(2150.00f, current)); + + //not valid + Assertions.assertEquals(null, customer.depositFunds(2150.00f, null)); + + + } + @Test + public void withdrawTest(){ + Customer customer = new Customer(); + ArrayList transactions = new ArrayList(); + Current current = new Current(0.00f, transactions ); + Savings savings = new Savings(0.00f, transactions ); + customer.depositFunds(10000.00f, savings); + customer.depositFunds(15000.00f, current); + + + + Assertions.assertEquals(2500.00f, customer.withdrawFunds(7500.00f, savings) ); + Assertions.assertEquals(500.00f, customer.withdrawFunds(500.00f, savings) ); + + + Assertions.assertEquals(10000.00f, customer.withdrawFunds(5000.00f, current) ); + + Assertions.assertEquals(500.00f, customer.withdrawFunds(9500.00f, current) ); + + //dont work + Assertions.assertEquals(-1.00f, customer.withdrawFunds(7500.00f, savings) ); + Assertions.assertEquals(-1.00f, customer.withdrawFunds(1000.00f, current) ); + Assertions.assertEquals(-1.00f, customer.withdrawFunds(501.00f, current) ); + + } + + @Test + public void bankStatementTest(){ + Customer customer = new Customer(); + ArrayList transactions = new ArrayList(); + Current current = new Current(0.00f, transactions ); + Savings savings = new Savings(0.00f, transactions ); + + + Assertions.assertEquals(" ", customer.generateBankStatement(current) ); + + + //add more deposits, how do I test it? should I just do booleans? + customer.depositFunds(10000.00f, savings); + //Assertions.assertEquals(" ", customer.generateBankStatement(current) ); + + customer.depositFunds(10000.00f, savings); + customer.depositFunds(15000.00f, current); + + } + + + + +} From af1c2c05d9548347701b28cf2a4eae4a2acf9c96 Mon Sep 17 00:00:00 2001 From: Emanuels Zaurins Date: Wed, 13 Aug 2025 13:52:59 +0200 Subject: [PATCH 2/3] green stage for coretest and redstage for extenstions --- src/main/domain-model.md | 52 +++++--- src/main/java/com/booleanuk/core/Account.java | 54 +++++++- src/main/java/com/booleanuk/core/Current.java | 6 +- .../java/com/booleanuk/core/Customer.java | 118 ++++++++++++++++- src/main/java/com/booleanuk/core/Savings.java | 6 +- .../java/com/booleanuk/core/Transaction.java | 28 +++- .../com/booleanuk/core/ExtensionTest.java | 124 ++++++++++++++++++ .../java/com/booleanuk/core/coreTest.java | 95 +++++++++----- 8 files changed, 413 insertions(+), 70 deletions(-) create mode 100644 src/test/java/com/booleanuk/core/ExtensionTest.java diff --git a/src/main/domain-model.md b/src/main/domain-model.md index 281604e45..9d0333a2a 100644 --- a/src/main/domain-model.md +++ b/src/main/domain-model.md @@ -14,21 +14,37 @@ 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(Account account) | if the account has transactions | return the bank statement | -| | | | if no transactions | return " " | -| | | | | | -| | | | | | -| | | | | | -| | | | | | -| | | | | | +| 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 | +| | | | | | +| | | | | | diff --git a/src/main/java/com/booleanuk/core/Account.java b/src/main/java/com/booleanuk/core/Account.java index 5f7f72701..4d5f239f5 100644 --- a/src/main/java/com/booleanuk/core/Account.java +++ b/src/main/java/com/booleanuk/core/Account.java @@ -1,13 +1,59 @@ package com.booleanuk.core; +import java.time.LocalDate; import java.util.ArrayList; -public class Account { +public abstract class Account { protected Float balance; protected ArrayList transactions; - public Account(Float balance, ArrayList transactions) { - this.balance = balance; + + public Account(ArrayList transactions) { + this.balance = 0.00f; this.transactions = transactions; } -} + + 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; + } + + + + } diff --git a/src/main/java/com/booleanuk/core/Current.java b/src/main/java/com/booleanuk/core/Current.java index b45a6ea78..c4188ee7b 100644 --- a/src/main/java/com/booleanuk/core/Current.java +++ b/src/main/java/com/booleanuk/core/Current.java @@ -4,7 +4,9 @@ public class Current extends Account{ - public Current(Float balance, ArrayList transactions) { - super(balance, transactions); + public Current(ArrayList transactions) { + super(transactions); } + + } diff --git a/src/main/java/com/booleanuk/core/Customer.java b/src/main/java/com/booleanuk/core/Customer.java index ebebfc0de..81b55ff8a 100644 --- a/src/main/java/com/booleanuk/core/Customer.java +++ b/src/main/java/com/booleanuk/core/Customer.java @@ -1,18 +1,122 @@ package com.booleanuk.core; +import java.util.ArrayList; + public class Customer { + Savings savings; + Current current; + Float requests; + enum Branch { + OSLO, BERGEN, HARDANGER + } + Customer.Branch branch; + + + public Customer() { + this.branch = Branch.BERGEN; + } + + public Boolean setBranch(String branch) { - public Boolean createAccount(String type){ return false; } - public Float withdrawFunds(Float amount, Account account){ - return 0.00f; + public Float overdraft(Float amount){ + return -1.00f; } - public Float depositFunds(Float amount, Account account){ - return 0.00f; + + public boolean createRequests(Float amount){ + return false; } - public Float generateBankStatement(Account account){ - return 0.00f; + + public boolean approveRequests(Float requests, boolean approved){ + 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()); + return true; + } + if (type.equalsIgnoreCase("CURRENT")){ + + current = new Current(new ArrayList()); + 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; + } } + diff --git a/src/main/java/com/booleanuk/core/Savings.java b/src/main/java/com/booleanuk/core/Savings.java index d4cd49979..cf7f97387 100644 --- a/src/main/java/com/booleanuk/core/Savings.java +++ b/src/main/java/com/booleanuk/core/Savings.java @@ -4,7 +4,9 @@ public class Savings extends Account { - public Savings(Float balance, ArrayList transactions) { - super(balance, transactions); + public Savings( ArrayList transactions) { + super(transactions); } + + } diff --git a/src/main/java/com/booleanuk/core/Transaction.java b/src/main/java/com/booleanuk/core/Transaction.java index 86b93aa1d..07d4c9b6a 100644 --- a/src/main/java/com/booleanuk/core/Transaction.java +++ b/src/main/java/com/booleanuk/core/Transaction.java @@ -1,16 +1,36 @@ package com.booleanuk.core; import java.time.LocalDate; +import java.util.Objects; public class Transaction { - private LocalDate date; - private Float amount; - private Float balance; + private final LocalDate date; + private final Float amount; + private final Float balance; + private final String type; - public Transaction(LocalDate date, Float amount, Float balance) { + 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; + } } diff --git a/src/test/java/com/booleanuk/core/ExtensionTest.java b/src/test/java/com/booleanuk/core/ExtensionTest.java new file mode 100644 index 000000000..b252795b6 --- /dev/null +++ b/src/test/java/com/booleanuk/core/ExtensionTest.java @@ -0,0 +1,124 @@ +package com.booleanuk.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; + +public class ExtensionTest { + @Test + public void getBalHardWayTest(){ + Customer customer = new Customer(); + ArrayList transactions = new ArrayList(); + Current current = new Current( transactions ); + Savings savings = new Savings(transactions ); + customer.createAccount("current"); + customer.createAccount("saVings"); + + Assertions.assertEquals(false, customer.generateBankStatement("current") ); + + + //add more deposits, how do I test it? should I just do booleans? + customer.depositFunds(10000.00f, "savings"); + //Assertions.assertEquals(" ", customer.generateBankStatement(current) ); + + customer.depositFunds(10000.00f, "savings"); + customer.depositFunds(15000.00f, "savings"); + Assertions.assertEquals(true, customer.generateBankStatement("savings") ); + customer.depositFunds(15000.00f, "savings"); + customer.depositFunds(15000.00f, "savings"); + customer.depositFunds(15000.00f, "savings"); + customer.depositFunds(125000.00f, "savings"); + customer.withdrawFunds(150000.00f, "savings"); + + Assertions.assertEquals(true, customer.generateBankStatement("savings") ); + Assertions.assertEquals(55000.00f, customer.getBalanceHardWay("savings") ); + + customer.depositFunds(10000.00f, "current"); + customer.depositFunds(100000.00f, "current"); + customer.withdrawFunds(50000.00f, "current"); + customer.withdrawFunds(50000.00f, "current"); + customer.depositFunds(100000.00f, "current"); + customer.withdrawFunds(50000.00f, "current"); + customer.withdrawFunds(60000.00f, "current"); + + + + Assertions.assertEquals(true, customer.generateBankStatement("current") ); + Assertions.assertEquals(0.00f, customer.getBalanceHardWay("current") ); + + + + } + + @Test + public void setBranchTest(){ + Customer customer = new Customer(); + ArrayList transactions = new ArrayList(); + Current current = new Current( transactions ); + Savings savings = new Savings(transactions ); + customer.createAccount("current"); + customer.createAccount("saVings"); + + Assertions.assertEquals(true, customer.setBranch("Oslo") ); + Assertions.assertEquals(false, customer.setBranch("Trondheim") ); + Assertions.assertEquals(true, customer.setBranch("Hardanger") ); + Assertions.assertEquals(true, customer.setBranch("BeRGen") ); + Assertions.assertEquals(false, customer.setBranch("Berrgen") ); + + + } + + @Test + public void overdraftTest(){ + Customer customer = new Customer(); + ArrayList transactions = new ArrayList(); + Current current = new Current( transactions ); + Savings savings = new Savings(transactions ); + customer.createAccount("current"); + customer.createAccount("saVings"); + + + customer.depositFunds(1000.00f, "current"); + Assertions.assertEquals(true, customer.overdraft(10100.00f) ); + + Assertions.assertEquals(true, customer.overdraft(50.00f) ); + + Assertions.assertEquals(false, customer.overdraft(100.00f) ); + customer.depositFunds(1000.00f, "savings"); + Assertions.assertEquals(false, customer.overdraft(900.00f) ); + System.out.println("overdraft----"); + customer.generateBankStatement("current"); + + + + } + + public void approveRequests(Float amount){ + Customer customer = new Customer(); + ArrayList transactions = new ArrayList(); + Current current = new Current( transactions ); + Savings savings = new Savings(transactions ); + customer.createAccount("current"); + customer.createAccount("saVings"); + + customer.depositFunds(1000.00f, "current"); + //try this + Assertions.assertEquals(true, customer.createRequests(1300.00f) ); + Assertions.assertEquals(true, customer.approveRequests(1300.00f,false) ); + Assertions.assertEquals(true, customer.createRequests(1300.00f) ); + Assertions.assertEquals(true, customer.approveRequests(1300.00f,true) ); + + customer.depositFunds(1300.00f, "current"); + + Assertions.assertEquals(true, customer.createRequests(1300.00f) ); + + Assertions.assertEquals(false, customer.approveRequests(1340.00f,true) ); + Assertions.assertEquals(false, customer.approveRequests(1300.00f,false) ); + Assertions.assertEquals(true, customer.approveRequests(1300.00f,true) ); + System.out.println("overdraft----"); + customer.generateBankStatement("current"); + } + + +} diff --git a/src/test/java/com/booleanuk/core/coreTest.java b/src/test/java/com/booleanuk/core/coreTest.java index b4db8203c..a90dedc34 100644 --- a/src/test/java/com/booleanuk/core/coreTest.java +++ b/src/test/java/com/booleanuk/core/coreTest.java @@ -11,35 +11,36 @@ public class coreTest { public void createAccountTest(){ Customer customer = new Customer(); ArrayList transactions = new ArrayList(); - Current current = new Current(0.00f, transactions ); - Savings savings = new Savings(0.00f, transactions ); + Current current = new Current( transactions ); + Savings savings = new Savings(transactions ); - Assertions.assertEquals(new Current(0.00f, transactions ), customer.createAccount("current")); + Assertions.assertEquals(true, customer.createAccount("current")); - Assertions.assertEquals(new Savings(0.00f, transactions ), customer.createAccount("savings")); + Assertions.assertEquals(true, customer.createAccount("saVings")); - Assertions.assertEquals(null, customer.createAccount("savngs")); - Assertions.assertEquals(null, customer.createAccount("curngs")); + Assertions.assertEquals(false, customer.createAccount("savngs")); + Assertions.assertEquals(false, customer.createAccount("curngs")); } @Test public void depositTest(){ Customer customer = new Customer(); ArrayList transactions = new ArrayList(); - Current current = new Current(0.00f, transactions ); - Savings savings = new Savings(0.00f, transactions ); + Current current = new Current( transactions ); + Savings savings = new Savings(transactions ); + customer.createAccount("current"); + customer.createAccount("saVings"); + Assertions.assertEquals(2500.00f, customer.depositFunds(2500.00f, "savings")); + Assertions.assertEquals(5000.00f, customer.depositFunds(2500.00f, "savings")); - Assertions.assertEquals(2500.00f, customer.depositFunds(2500.00f, savings)); - Assertions.assertEquals(5000.00f, customer.depositFunds(2500.00f, savings)); + Assertions.assertEquals(2500.00f, customer.depositFunds(2500.00f, "current")); + Assertions.assertEquals(5000.00f, customer.depositFunds(2500.00f, "current")); - Assertions.assertEquals(2500.00f, customer.depositFunds(2500.00f, current)); - Assertions.assertEquals(5000.00f, customer.depositFunds(2500.00f, current)); - - Assertions.assertEquals(7150.00f, customer.depositFunds(2150.00f, current)); + Assertions.assertEquals(7150.00f, customer.depositFunds(2150.00f, "savings")); //not valid - Assertions.assertEquals(null, customer.depositFunds(2150.00f, null)); + Assertions.assertEquals(-1.00f, customer.depositFunds(2150.00f, "sds")); } @@ -47,25 +48,31 @@ public void depositTest(){ public void withdrawTest(){ Customer customer = new Customer(); ArrayList transactions = new ArrayList(); - Current current = new Current(0.00f, transactions ); - Savings savings = new Savings(0.00f, transactions ); - customer.depositFunds(10000.00f, savings); - customer.depositFunds(15000.00f, current); + Current current = new Current( transactions ); + Savings savings = new Savings(transactions ); + customer.createAccount("current"); + customer.createAccount("saVings"); + customer.depositFunds(10000.00f, "savings"); + customer.depositFunds(15000.00f, "current"); - Assertions.assertEquals(2500.00f, customer.withdrawFunds(7500.00f, savings) ); - Assertions.assertEquals(500.00f, customer.withdrawFunds(500.00f, savings) ); + Assertions.assertEquals(2500.00f, customer.withdrawFunds(7500.00f, "savings") ); + Assertions.assertEquals(2000.00f, customer.withdrawFunds(500.00f, "savings") ); - Assertions.assertEquals(10000.00f, customer.withdrawFunds(5000.00f, current) ); + Assertions.assertEquals(10000.00f, customer.withdrawFunds(5000.00f, "current") ); - Assertions.assertEquals(500.00f, customer.withdrawFunds(9500.00f, current) ); + Assertions.assertEquals(500.00f, customer.withdrawFunds(9500.00f, "current") ); //dont work - Assertions.assertEquals(-1.00f, customer.withdrawFunds(7500.00f, savings) ); - Assertions.assertEquals(-1.00f, customer.withdrawFunds(1000.00f, current) ); - Assertions.assertEquals(-1.00f, customer.withdrawFunds(501.00f, current) ); + Assertions.assertEquals(-1.00f, customer.withdrawFunds(7500.00f, "savings") ); + Assertions.assertEquals(-1.00f, customer.withdrawFunds(2500.00f, "savings") ); + Assertions.assertEquals(-1.00f, customer.withdrawFunds(501.00f, "current") ); + + + Assertions.assertEquals(00.00f, customer.withdrawFunds(500.00f, "current") ); + } @@ -73,19 +80,41 @@ public void withdrawTest(){ public void bankStatementTest(){ Customer customer = new Customer(); ArrayList transactions = new ArrayList(); - Current current = new Current(0.00f, transactions ); - Savings savings = new Savings(0.00f, transactions ); - + Current current = new Current( transactions ); + Savings savings = new Savings(transactions ); + customer.createAccount("current"); + customer.createAccount("saVings"); - Assertions.assertEquals(" ", customer.generateBankStatement(current) ); + Assertions.assertEquals(false, customer.generateBankStatement("current") ); //add more deposits, how do I test it? should I just do booleans? - customer.depositFunds(10000.00f, savings); + customer.depositFunds(10000.00f, "savings"); //Assertions.assertEquals(" ", customer.generateBankStatement(current) ); - customer.depositFunds(10000.00f, savings); - customer.depositFunds(15000.00f, current); + customer.depositFunds(10000.00f, "savings"); + customer.depositFunds(15000.00f, "savings"); + Assertions.assertEquals(true, customer.generateBankStatement("savings") ); + customer.depositFunds(15000.00f, "savings"); + customer.depositFunds(15000.00f, "savings"); + customer.depositFunds(15000.00f, "savings"); + customer.depositFunds(125000.00f, "savings"); + customer.withdrawFunds(150000.00f, "savings"); + + Assertions.assertEquals(true, customer.generateBankStatement("savings") ); + + customer.depositFunds(10000.00f, "current"); + customer.depositFunds(100000.00f, "current"); + customer.withdrawFunds(50000.00f, "current"); + customer.withdrawFunds(50000.00f, "current"); + customer.depositFunds(100000.00f, "current"); + customer.withdrawFunds(50000.00f, "current"); + customer.withdrawFunds(60000.00f, "current"); + + + + Assertions.assertEquals(true, customer.generateBankStatement("current") ); + } From f63415cec73669a9e6b2b14322416e0651539e04 Mon Sep 17 00:00:00 2001 From: Emanuels Zaurins Date: Wed, 13 Aug 2025 14:41:38 +0200 Subject: [PATCH 3/3] Green stage for extensions except SMS --- src/main/java/com/booleanuk/core/Account.java | 24 ++++++++++++++ src/main/java/com/booleanuk/core/Current.java | 1 + .../java/com/booleanuk/core/Customer.java | 31 +++++++++++++++---- .../com/booleanuk/core/ExtensionTest.java | 18 +++++------ 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Account.java b/src/main/java/com/booleanuk/core/Account.java index 4d5f239f5..2f755a6fb 100644 --- a/src/main/java/com/booleanuk/core/Account.java +++ b/src/main/java/com/booleanuk/core/Account.java @@ -2,17 +2,41 @@ import java.time.LocalDate; import java.util.ArrayList; +import java.util.Objects; public abstract class Account { protected Float balance; protected ArrayList transactions; + protected ArrayList requests; + + public Account(ArrayList transactions) { this.balance = 0.00f; this.transactions = transactions; + this.requests = new ArrayList(); + } + + 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, "+")); diff --git a/src/main/java/com/booleanuk/core/Current.java b/src/main/java/com/booleanuk/core/Current.java index c4188ee7b..421dd973b 100644 --- a/src/main/java/com/booleanuk/core/Current.java +++ b/src/main/java/com/booleanuk/core/Current.java @@ -9,4 +9,5 @@ public Current(ArrayList transactions) { } + } diff --git a/src/main/java/com/booleanuk/core/Customer.java b/src/main/java/com/booleanuk/core/Customer.java index 81b55ff8a..db5a58fa8 100644 --- a/src/main/java/com/booleanuk/core/Customer.java +++ b/src/main/java/com/booleanuk/core/Customer.java @@ -5,7 +5,6 @@ public class Customer { Savings savings; Current current; - Float requests; enum Branch { OSLO, BERGEN, HARDANGER } @@ -16,19 +15,39 @@ public Customer() { this.branch = Branch.BERGEN; } - public Boolean setBranch(String branch) { - - return false; + public Boolean setBranch(Customer.Branch branch) { + this.branch = branch; + return true; } - public Float overdraft(Float amount){ - return -1.00f; + 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; } diff --git a/src/test/java/com/booleanuk/core/ExtensionTest.java b/src/test/java/com/booleanuk/core/ExtensionTest.java index b252795b6..ad54fc15a 100644 --- a/src/test/java/com/booleanuk/core/ExtensionTest.java +++ b/src/test/java/com/booleanuk/core/ExtensionTest.java @@ -5,6 +5,8 @@ import java.util.ArrayList; +import static com.booleanuk.core.Customer.Branch.*; + public class ExtensionTest { @Test public void getBalHardWayTest(){ @@ -60,11 +62,9 @@ public void setBranchTest(){ customer.createAccount("current"); customer.createAccount("saVings"); - Assertions.assertEquals(true, customer.setBranch("Oslo") ); - Assertions.assertEquals(false, customer.setBranch("Trondheim") ); - Assertions.assertEquals(true, customer.setBranch("Hardanger") ); - Assertions.assertEquals(true, customer.setBranch("BeRGen") ); - Assertions.assertEquals(false, customer.setBranch("Berrgen") ); + Assertions.assertEquals(true, customer.setBranch(OSLO) ); + Assertions.assertEquals(true, customer.setBranch(HARDANGER) ); + Assertions.assertEquals(true, customer.setBranch(BERGEN) ); } @@ -80,7 +80,7 @@ public void overdraftTest(){ customer.depositFunds(1000.00f, "current"); - Assertions.assertEquals(true, customer.overdraft(10100.00f) ); + Assertions.assertEquals(true, customer.overdraft(1100.00f) ); Assertions.assertEquals(true, customer.overdraft(50.00f) ); @@ -93,8 +93,8 @@ public void overdraftTest(){ } - - public void approveRequests(Float amount){ + @Test + public void approveRequests(){ Customer customer = new Customer(); ArrayList transactions = new ArrayList(); Current current = new Current( transactions ); @@ -105,7 +105,7 @@ public void approveRequests(Float amount){ customer.depositFunds(1000.00f, "current"); //try this Assertions.assertEquals(true, customer.createRequests(1300.00f) ); - Assertions.assertEquals(true, customer.approveRequests(1300.00f,false) ); + Assertions.assertEquals(false, customer.approveRequests(1300.00f,false) ); Assertions.assertEquals(true, customer.createRequests(1300.00f) ); Assertions.assertEquals(true, customer.approveRequests(1300.00f,true) );