From 923563424977f051cc4e96801d9863ec48a6e0fd Mon Sep 17 00:00:00 2001 From: hazel Date: Fri, 12 Mar 2021 16:58:20 -0500 Subject: [PATCH 01/35] Tentative UML finished --- src/uml.puml | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/uml.puml diff --git a/src/uml.puml b/src/uml.puml new file mode 100644 index 0000000..116d6e7 --- /dev/null +++ b/src/uml.puml @@ -0,0 +1,60 @@ +@startuml + +class MainApplication{ + run(); +} + +class Customer{ + Map credentials; + ArrayList ownedAccounts; + String name; + + createUser(); +} + +class Display{ + String currentDisplay; + String menu; + String transactionHistory; + + //getters and setters(); +} + +class Console{ + getDoubleInput(Double); + getStringInput(String); +} + +abstract class Account{ + Map cashMoneys; + Double currentBalance; + Integer accountNumber; + + openNewAccount(Integer); + //getters and setters(); +} + +class Transactions{ + getBalance(); + transfer(Double); + withdraw(Double); + closeAccount(Integer); +} + +class Investment{ + //inherits stuff +} + +class Savings{ + //inherits stuff +} + +class Checking{ + //inherits stuff +} + +Account <|-- Investment +Account <|-- Savings +Account <|-- Checking + +@enduml \ No newline at end of file From 889be649b191f8de996387945488c955f0d1ca27 Mon Sep 17 00:00:00 2001 From: hazel Date: Fri, 12 Mar 2021 18:12:28 -0500 Subject: [PATCH 02/35] Began Display/Console --- src/main/java/Console.java | 27 +++++++++++++++++++++++++++ src/main/java/Display.java | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/main/java/Console.java create mode 100644 src/main/java/Display.java diff --git a/src/main/java/Console.java b/src/main/java/Console.java new file mode 100644 index 0000000..2a29893 --- /dev/null +++ b/src/main/java/Console.java @@ -0,0 +1,27 @@ +import java.util.Scanner; + +public class Console { + + public static void print(String output, Object... args) { + System.out.printf(output, args); + } + + public static void println(String output, Object... args) { + print(output + "\n", args); + } + + public String getStringInput(String prompt) { + Scanner scanner = new Scanner(System.in); + println(prompt); + String userInput = scanner.nextLine(); + return userInput; + } + + public Double getDoubleInput(String prompt) { + Scanner scanner = new Scanner(System.in); + println(prompt); + Double userInput = scanner.nextDouble(); + return userInput; + } + +} diff --git a/src/main/java/Display.java b/src/main/java/Display.java new file mode 100644 index 0000000..0be6254 --- /dev/null +++ b/src/main/java/Display.java @@ -0,0 +1,36 @@ +public class Display { + + String currentDisplay; + String menu; + String transactionHistory; + + public Display(){ + this.currentDisplay = ""; + this.menu = ""; + this.transactionHistory = ""; + } + + public String getCurrentDisplay() { + return currentDisplay; + } + + public void setCurrentDisplay(String currentDisplay) { + this.currentDisplay = currentDisplay; + } + + public String getMenu() { + return menu; + } + + public void setMenu(String menu) { + this.menu = menu; + } + + public String getTransactionHistory() { + return transactionHistory; + } + + public void setTransactionHistory(String transactionHistory) { + this.transactionHistory = transactionHistory; + } +} From 890237e15ead41e64a470c8d4fc9f2179fe5e6fb Mon Sep 17 00:00:00 2001 From: xiong Date: Fri, 12 Mar 2021 19:45:10 -0500 Subject: [PATCH 03/35] created Account classes and wrote some tests --- pom.xml | 7 ++++ src/main/java/Account.java | 34 ++++++++++++++++++ src/main/java/Checking.java | 24 +++++++++++++ src/main/java/Investment.java | 24 +++++++++++++ src/main/java/Savings.java | 24 +++++++++++++ src/main/test/java/CheckingTest.java | 52 ++++++++++++++++++++++++++++ 6 files changed, 165 insertions(+) create mode 100644 src/main/java/Account.java create mode 100644 src/main/java/Checking.java create mode 100644 src/main/java/Investment.java create mode 100644 src/main/java/Savings.java create mode 100644 src/main/test/java/CheckingTest.java diff --git a/pom.xml b/pom.xml index 9901415..19115ef 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,13 @@ io.zipcoder project-2-atm 1.0-SNAPSHOT + + + junit + junit + 4.11 + + \ No newline at end of file diff --git a/src/main/java/Account.java b/src/main/java/Account.java new file mode 100644 index 0000000..9d193b4 --- /dev/null +++ b/src/main/java/Account.java @@ -0,0 +1,34 @@ +public abstract class Account { + private final Integer accountNumber; + private double balance; + + protected Account(Integer accountNumber, double balance) { + this.accountNumber = accountNumber; + this.balance = balance; + } + + public int getAccountNumber() { + return accountNumber; + } + + public double getBalance() { + return balance; + } + + public void setBalance(double balance) { + this.balance = balance; + } + + public double withdraw(double amount) { + if (balance > amount && balance - amount >= 0) { + balance -= amount; + } + return balance; + } + + public double deposit(double amount) { + return balance + amount; + } + + +} diff --git a/src/main/java/Checking.java b/src/main/java/Checking.java new file mode 100644 index 0000000..9ac1cee --- /dev/null +++ b/src/main/java/Checking.java @@ -0,0 +1,24 @@ +public class Checking extends Account{ + + public Checking(Integer accountNumber, double balance) { + super(accountNumber,balance); + } + + public double transferToSavings(Savings savingsAccount, double transferAmount) { + if (this.getBalance() > transferAmount && this.getBalance() - transferAmount >= 0) { + this.withdraw(transferAmount); + savingsAccount.deposit(transferAmount); + } + + return this.getBalance(); + } + + public double transferToInvestment(Investment investmentAccount, double transferAmount) { + if (this.getBalance() > transferAmount && this.getBalance() - transferAmount >= 0) { + this.withdraw(transferAmount); + investmentAccount.deposit(transferAmount); + } + + return this.getBalance(); + } +} diff --git a/src/main/java/Investment.java b/src/main/java/Investment.java new file mode 100644 index 0000000..eb6d993 --- /dev/null +++ b/src/main/java/Investment.java @@ -0,0 +1,24 @@ +public class Investment extends Account { + + public Investment(Integer accountNumber, double balance) { + super(accountNumber, balance); + } + + public double transferToSavings(Savings savingsAccount, double transferAmount) { + if (this.getBalance() > transferAmount && this.getBalance() - transferAmount >= 0) { + this.withdraw(transferAmount); + savingsAccount.deposit(transferAmount); + } + + return this.getBalance(); + } + + public double transferToChecking(Checking checkingAccount, double transferAmount) { + if (this.getBalance() > transferAmount && this.getBalance() - transferAmount >= 0) { + this.withdraw(transferAmount); + checkingAccount.deposit(transferAmount); + } + + return this.getBalance(); + } +} diff --git a/src/main/java/Savings.java b/src/main/java/Savings.java new file mode 100644 index 0000000..7931ef4 --- /dev/null +++ b/src/main/java/Savings.java @@ -0,0 +1,24 @@ +public class Savings extends Account{ + + public Savings(Integer accountNumber, double balance) { + super(accountNumber, balance); + } + + public double transferToChecking(Checking checkingAccount, double transferAmount) { + if (this.getBalance() > transferAmount && this.getBalance() - transferAmount >= 0) { + this.withdraw(transferAmount); + checkingAccount.deposit(transferAmount); + } + + return this.getBalance(); + } + + public double transferToInvestment(Investment investmentAccount, double transferAmount) { + if (this.getBalance() > transferAmount && this.getBalance() - transferAmount >= 0) { + this.withdraw(transferAmount); + investmentAccount.deposit(transferAmount); + } + + return this.getBalance(); + } +} diff --git a/src/main/test/java/CheckingTest.java b/src/main/test/java/CheckingTest.java new file mode 100644 index 0000000..d335792 --- /dev/null +++ b/src/main/test/java/CheckingTest.java @@ -0,0 +1,52 @@ +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CheckingTest { + + @Test + public void testConstructor() { + // : Given + Integer accountChecking = 14104244; + double initialDeposit = 1000.00; + + // : When + Checking checking101 = new Checking(accountChecking, initialDeposit); + Integer actualAccountNumber = checking101.getAccountNumber(); + double actualBalance = checking101.getBalance(); + + // : Then + Assert.assertEquals(accountChecking, actualAccountNumber); + Assert.assertEquals(initialDeposit, actualBalance, 0.00001); + } + + @Test + public void testTransferToSavings() { + // : Given + Integer accountChecking = 14104244; + Integer accountSavings = 160811456; + double initialDeposit = 1000.00; + Checking checking101 = new Checking(accountChecking, initialDeposit); + Savings savings101 = new Savings(accountSavings, initialDeposit); + + // : When + double expectedCheckingBalance = 800; + double expectedSavingsBalance = 1200; + double actualCheckingBalance = checking101.transferToSavings(savings101, 200); + double actualSavingsBalance = savings101.getBalance(); + + System.out.println(checking101.getBalance()); + System.out.println(savings101.getBalance()); + + // : Then + Assert.assertEquals(expectedCheckingBalance, actualCheckingBalance, 0.000001); + Assert.assertEquals(expectedSavingsBalance, actualSavingsBalance, 0.000001); + + + } + + @Test + public void transferToInvestment() { + } +} \ No newline at end of file From 17195254ade8bba09d05e74518799176f26d965f Mon Sep 17 00:00:00 2001 From: xiong Date: Fri, 12 Mar 2021 20:01:24 -0500 Subject: [PATCH 04/35] removed setBalance() and fixed deposit() + Unit Test --- src/main/java/Account.java | 6 +-- src/main/java/Checking.java | 8 ++-- src/main/test/java/CheckingTest.java | 58 ++++++++++++++++++++++++++-- 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/src/main/java/Account.java b/src/main/java/Account.java index 9d193b4..6a39c72 100644 --- a/src/main/java/Account.java +++ b/src/main/java/Account.java @@ -15,10 +15,6 @@ public double getBalance() { return balance; } - public void setBalance(double balance) { - this.balance = balance; - } - public double withdraw(double amount) { if (balance > amount && balance - amount >= 0) { balance -= amount; @@ -27,7 +23,7 @@ public double withdraw(double amount) { } public double deposit(double amount) { - return balance + amount; + return balance += amount; } diff --git a/src/main/java/Checking.java b/src/main/java/Checking.java index 9ac1cee..681e908 100644 --- a/src/main/java/Checking.java +++ b/src/main/java/Checking.java @@ -4,21 +4,19 @@ public Checking(Integer accountNumber, double balance) { super(accountNumber,balance); } - public double transferToSavings(Savings savingsAccount, double transferAmount) { + public void transferToSavings(Savings savingsAccount, double transferAmount) { if (this.getBalance() > transferAmount && this.getBalance() - transferAmount >= 0) { this.withdraw(transferAmount); savingsAccount.deposit(transferAmount); } - return this.getBalance(); + //return this.getBalance(); } - public double transferToInvestment(Investment investmentAccount, double transferAmount) { + public void transferToInvestment(Investment investmentAccount, double transferAmount) { if (this.getBalance() > transferAmount && this.getBalance() - transferAmount >= 0) { this.withdraw(transferAmount); investmentAccount.deposit(transferAmount); } - - return this.getBalance(); } } diff --git a/src/main/test/java/CheckingTest.java b/src/main/test/java/CheckingTest.java index d335792..363681d 100644 --- a/src/main/test/java/CheckingTest.java +++ b/src/main/test/java/CheckingTest.java @@ -21,6 +21,38 @@ public void testConstructor() { Assert.assertEquals(initialDeposit, actualBalance, 0.00001); } + @Test + public void testWithdraw() { + // : Given + Integer accountChecking = 14104244; + double initialDeposit = 1000.00; + Checking checking101 = new Checking(accountChecking, initialDeposit); + + // : When + checking101.withdraw(750); + double expected = 250.00; + double actual = checking101.getBalance(); + + // : Then + Assert.assertEquals(expected, actual, 0.00001); + } + + @Test + public void testDeposit() { + // : Given + Integer accountChecking = 14104244; + double initialDeposit = 1000.00; + Checking checking101 = new Checking(accountChecking, initialDeposit); + + // : When + checking101.deposit(750); + double expected = 1750.00; + double actual = checking101.getBalance(); + + // : Then + Assert.assertEquals(expected, actual, 0.00001); + } + @Test public void testTransferToSavings() { // : Given @@ -33,7 +65,8 @@ public void testTransferToSavings() { // : When double expectedCheckingBalance = 800; double expectedSavingsBalance = 1200; - double actualCheckingBalance = checking101.transferToSavings(savings101, 200); + checking101.transferToSavings(savings101, 200); + double actualCheckingBalance = checking101.getBalance(); double actualSavingsBalance = savings101.getBalance(); System.out.println(checking101.getBalance()); @@ -42,11 +75,30 @@ public void testTransferToSavings() { // : Then Assert.assertEquals(expectedCheckingBalance, actualCheckingBalance, 0.000001); Assert.assertEquals(expectedSavingsBalance, actualSavingsBalance, 0.000001); - - } @Test public void transferToInvestment() { + // : Given + Integer accountChecking = 14104244; + Integer accountInvestment = 18095386; + double initialCheckingDeposit = 1000.00; + double initialInvestmentDeposit = 50000; + Checking checking101 = new Checking(accountChecking, initialCheckingDeposit); + Investment investment101 = new Investment(accountInvestment, initialInvestmentDeposit); + + // : When + double expectedCheckingBalance = 200; + double expectedInvestmentBalance = 50800; + checking101.transferToInvestment(investment101, 800); + double actualCheckingBalance = checking101.getBalance(); + double actualInvestmentBalance = investment101.getBalance(); + + System.out.println(checking101.getBalance()); + System.out.println(investment101.getBalance()); + + // : Then + Assert.assertEquals(expectedCheckingBalance, actualCheckingBalance, 0.000001); + Assert.assertEquals(expectedInvestmentBalance, actualInvestmentBalance, 0.000001); } } \ No newline at end of file From c89fda92fdd53ed076f02f44b64e75d0338cbacf Mon Sep 17 00:00:00 2001 From: mike Date: Fri, 12 Mar 2021 20:58:41 -0500 Subject: [PATCH 05/35] did Customer --- src/main/java/Customer.java | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/Customer.java diff --git a/src/main/java/Customer.java b/src/main/java/Customer.java new file mode 100644 index 0000000..19f12b2 --- /dev/null +++ b/src/main/java/Customer.java @@ -0,0 +1,43 @@ +import java.util.ArrayList; +import java.util.List; + +public class Customer { + + private String userName; + private String passWord; + private ArrayList accountNumbers = new ArrayList(); + private Integer accountNum; + + + public Customer(String userName, String passWord, Integer accountNum){ + this.userName = userName; + this.passWord = passWord; + this.accountNum = accountNum; + } + + public String getUserName(){ + return this.userName; + } + + public void setUserName(String userName){ + this.userName = userName; + } + + public String getPassWord(){ + return this.passWord; + } + + public void setPassWord(String passWord){ + this.userName = passWord; + } + + public ArrayList getAccountNumbers() { + return accountNumbers; + } + + public void setAccountNumbers(String userName, String passWord, Integer accountNum) { + Customer accountNumbers = new Customer(userName, passWord, accountNum); + this.accountNumbers.add(accountNumbers); + } + +} From e229de1da24e7ea4f81d22ba7151b4afc46de156 Mon Sep 17 00:00:00 2001 From: hazel Date: Fri, 12 Mar 2021 21:12:33 -0500 Subject: [PATCH 06/35] More console code --- src/main/java/Console.java | 10 ++++++++++ src/main/java/Main.java | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/Console.java b/src/main/java/Console.java index 2a29893..3a9ba78 100644 --- a/src/main/java/Console.java +++ b/src/main/java/Console.java @@ -15,6 +15,15 @@ public String getStringInput(String prompt) { println(prompt); String userInput = scanner.nextLine(); return userInput; + + } + + public Integer getIntegerInput(String prompt) { + Scanner scanner = new Scanner(System.in); + println(prompt); + Integer userInput = scanner.nextInt(); + return userInput; + } public Double getDoubleInput(String prompt) { @@ -22,6 +31,7 @@ public Double getDoubleInput(String prompt) { println(prompt); Double userInput = scanner.nextDouble(); return userInput; + } } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 05e41a9..1dbc0cb 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -4,6 +4,6 @@ public class Main { public static void main(String[] args){ - + } } From e28faf540cb268f5ec622255302903a9f7741e3d Mon Sep 17 00:00:00 2001 From: lena Date: Fri, 12 Mar 2021 23:04:09 -0500 Subject: [PATCH 07/35] testInvestment done --- src/main/test/java/InvestmentTest.java | 74 ++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/main/test/java/InvestmentTest.java diff --git a/src/main/test/java/InvestmentTest.java b/src/main/test/java/InvestmentTest.java new file mode 100644 index 0000000..21f4f19 --- /dev/null +++ b/src/main/test/java/InvestmentTest.java @@ -0,0 +1,74 @@ +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Test; + +public class InvestmentTest { + @Test + public void testConstructor(){ + // : Given +Integer expectedAccountNumber = 777777777; +Double expectedBalance = 1200.0; +Investment investmentZero=new Investment(expectedAccountNumber,expectedBalance); + + // : When + + Integer actualAccountNumber=investmentZero.getAccountNumber(); + double actualBalance=investmentZero.getBalance(); + + // : Then + Assert.assertEquals(expectedAccountNumber,actualAccountNumber); + Assert.assertEquals(expectedBalance,actualBalance,0.00001); + } + + @Test + public void testTransferToSavings(){ + // : Given + Integer investementAccountNumber = 777777777; + double investmentAccountBalance = 12000.0; + Integer savingsAccountNumber =11111111; + double savingsAccountBalance=7000.0; + Investment investmentZero=new Investment(investementAccountNumber,investmentAccountBalance); + Savings savingsZero=new Savings(savingsAccountNumber,savingsAccountBalance); + // : When + double transferAmountToSaving=3000.0; + double expectedInvestmentAccountBalance=9000.0; + double expectedSavingsAccountBalance=10000.0; + investmentZero.transferToSavings(savingsZero,transferAmountToSaving); + double actualInvestmentAccountBalance=investmentZero.getBalance(); + double actualSavigsAccountBalance=savingsZero.getBalance(); + + System.out.println(investmentZero.getBalance()); + System.out.println(savingsZero.getBalance()); + + // : Then + Assert.assertEquals(expectedInvestmentAccountBalance,actualInvestmentAccountBalance,0.0000001); + Assert.assertEquals(expectedSavingsAccountBalance,actualSavigsAccountBalance, 0.000001); + + } + @Test + public void testTransferToChecking(){ + // : Given + Integer investementAccountNumber = 888888888; + double investmentAccountBalance = 9000.0; + Integer checkingAccountNumber =00077777666; + double checkingAccountBalance=5000.0; + Investment investmentZero=new Investment(investementAccountNumber,investmentAccountBalance); + Checking checkingZero=new Checking(checkingAccountNumber,checkingAccountBalance); + // : When + double transferAmountToChecking=500.0; + double expectedInvestmentAccountBalance=8500.0; + double expectedCheckingAccountBalance=5500.0; + investmentZero.transferToChecking(checkingZero,transferAmountToChecking); + double actualInvestmentAccountBalance=investmentZero.getBalance(); + double actualCheckingAccountBalance=checkingZero.getBalance(); + + System.out.println(investmentZero.getBalance()); + System.out.println(checkingZero.getBalance()); + + + // : Then + Assert.assertEquals(expectedInvestmentAccountBalance,actualInvestmentAccountBalance,0.0000001); + Assert.assertEquals(expectedCheckingAccountBalance,actualCheckingAccountBalance, 0.000001); + +} +} \ No newline at end of file From 4e336e3d95880815173d0cf1aa082d449957ca6b Mon Sep 17 00:00:00 2001 From: lena Date: Fri, 12 Mar 2021 23:47:44 -0500 Subject: [PATCH 08/35] tests for SavingAccount --- src/main/java/Savings.java | 2 + src/main/test/java/SavingsTest.java | 74 +++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/main/test/java/SavingsTest.java diff --git a/src/main/java/Savings.java b/src/main/java/Savings.java index 7931ef4..d1eb5ee 100644 --- a/src/main/java/Savings.java +++ b/src/main/java/Savings.java @@ -9,6 +9,7 @@ public double transferToChecking(Checking checkingAccount, double transferAmount this.withdraw(transferAmount); checkingAccount.deposit(transferAmount); } + else System.out.println("Non sufficient funds"); return this.getBalance(); } @@ -18,6 +19,7 @@ public double transferToInvestment(Investment investmentAccount, double transfer this.withdraw(transferAmount); investmentAccount.deposit(transferAmount); } + else System.out.println("Non sufficient funds"); return this.getBalance(); } diff --git a/src/main/test/java/SavingsTest.java b/src/main/test/java/SavingsTest.java new file mode 100644 index 0000000..d60fddb --- /dev/null +++ b/src/main/test/java/SavingsTest.java @@ -0,0 +1,74 @@ +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Test; + +public class SavingsTest { +@Test + +// : Given + public void testSavingsAccount(){ + Integer savingsAccountNumber=9999999; + double savingsAccountBalance=1300.0; + Savings savingsZero=new Savings(savingsAccountNumber,savingsAccountBalance); +// : When + + Integer actualSavingsAccountNumber=savingsZero.getAccountNumber(); + double actualSavingsAccountBalance=savingsZero.getBalance(); + +// : Then + Assert.assertEquals(savingsAccountNumber,actualSavingsAccountNumber, 0.00001); + Assert.assertEquals(savingsAccountBalance,actualSavingsAccountBalance, 0.00001); +} +@Test +public void testTransferToCheckingAccount(){ + // : Given + Integer savingsAccountNumber = 343234321; + double savingsAccountBalance = 0.0; + Integer checkingAccountNumber =89898998; + double checkingAccountBalance=8000.0; + Checking checkingZero=new Checking(checkingAccountNumber,checkingAccountBalance); + Savings savingsZero=new Savings(savingsAccountNumber,savingsAccountBalance); + // : When + double transferAmountToChecking=3000.0; + double expectedCheckingAccountBalance=8000.0; + double expectedSavingsAccountBalance=0.0; + savingsZero.transferToChecking(checkingZero,transferAmountToChecking); + double actualCheckingAccountBalance=checkingZero.getBalance(); + double actualSavigsAccountBalance=savingsZero.getBalance(); + + System.out.println(checkingZero.getBalance()); + System.out.println(savingsZero.getBalance()); + + // : Then + Assert.assertEquals(expectedCheckingAccountBalance,actualCheckingAccountBalance,0.0000001); + Assert.assertEquals(expectedSavingsAccountBalance,actualSavigsAccountBalance, 0.000001); + + } + @Test + public void testTransferToInvestment(){ + // : Given + Integer savingsAccountNumber = 7777777; + double savingsAccountBalance = 6000.0; + Integer investementAccountNumber = 5555555; + double investmentAccountBalance = 1000.0; + Savings savingsZero=new Savings(savingsAccountNumber,savingsAccountBalance); + Investment investmentZero=new Investment(investementAccountNumber,investmentAccountBalance); + + // : When + double transferAmountToInvestment=500.0; + double expectedInvestmentAccountBalance=1500.0; + double expectedSavingsAccountBalance=5500.0; + savingsZero.transferToInvestment(investmentZero,transferAmountToInvestment); + double actualInvestmentAccountBalance=investmentZero.getBalance(); + double actualSavingsAccountBalance=savingsZero.getBalance(); + + System.out.println(investmentZero.getBalance()); + System.out.println(savingsZero.getBalance()); + + + // : Then + Assert.assertEquals(expectedInvestmentAccountBalance,actualInvestmentAccountBalance,0.0000001); + Assert.assertEquals(expectedSavingsAccountBalance,actualSavingsAccountBalance, 0.000001); + + } +} \ No newline at end of file From 9c0a4bb35a625f0770a2b31e2e5bab26fb425fb7 Mon Sep 17 00:00:00 2001 From: mike Date: Sat, 13 Mar 2021 09:05:43 -0500 Subject: [PATCH 09/35] almost done with test missing last one --- src/main/java/Customer.java | 37 ++++--- src/main/test/java/CustomerTest.java | 141 +++++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 16 deletions(-) create mode 100644 src/main/test/java/CustomerTest.java diff --git a/src/main/java/Customer.java b/src/main/java/Customer.java index 19f12b2..7b35d6d 100644 --- a/src/main/java/Customer.java +++ b/src/main/java/Customer.java @@ -1,20 +1,25 @@ import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class Customer { - + private String customerName; private String userName; - private String passWord; - private ArrayList accountNumbers = new ArrayList(); - private Integer accountNum; + private String password; + private List accounts = new ArrayList(); - public Customer(String userName, String passWord, Integer accountNum){ + public Customer(String customerName, String userName, String password, Account[] accounts){ + this.customerName = customerName; this.userName = userName; - this.passWord = passWord; - this.accountNum = accountNum; + this.password = password; + this.accounts = Arrays.asList(accounts); } + public String getCustomerName(){ return this.customerName;} + + public void setCustomerName(String customerName){ this.customerName = customerName;} + public String getUserName(){ return this.userName; } @@ -23,21 +28,21 @@ public void setUserName(String userName){ this.userName = userName; } - public String getPassWord(){ - return this.passWord; + public String getPassword(){ + return this.password; } - public void setPassWord(String passWord){ - this.userName = passWord; + public void setPassword(String password){ + this.password = password; } - public ArrayList getAccountNumbers() { + public String getAccountNumber() { + String accountNumbers = ""; + for(int i = 0; i < accounts.size(); i++) { + accountNumbers += String.format("%s ", accounts.get(i).getAccountNumber()); + } return accountNumbers; } - public void setAccountNumbers(String userName, String passWord, Integer accountNum) { - Customer accountNumbers = new Customer(userName, passWord, accountNum); - this.accountNumbers.add(accountNumbers); - } } diff --git a/src/main/test/java/CustomerTest.java b/src/main/test/java/CustomerTest.java new file mode 100644 index 0000000..e918107 --- /dev/null +++ b/src/main/test/java/CustomerTest.java @@ -0,0 +1,141 @@ +import org.junit.Assert; +import org.junit.Test; + +public class CustomerTest { + + @Test + public void customerConstuctor() { + // : Given + String customerName = "Xiong Yuan"; + String userName = "xyuan"; + String password = "zipcode0"; + Account checkingAccount = new Checking(24231, 23142); + Account[] accounts = new Account[]{checkingAccount}; + + // : When + Customer xiong = new Customer(customerName, userName, password, accounts); + String actualName = xiong.getCustomerName(); + String actualUserName = xiong.getUserName(); + String actualPassword = xiong.getPassword(); + String account = "242341"; + + // : Then + Assert.assertEquals(customerName, actualName); + Assert.assertEquals(userName, actualUserName); + Assert.assertEquals(password, actualPassword); + Assert.assertEquals(account, accounts); + + } + + + @Test + public void getCustomerName() { + // : Given + String customerName = "Lena Litouka"; + String userName = "llitouka"; + String password = "zipcode0"; + Account checkingAccount = new Checking(23142, 23214); + Account[] accounts = new Account[]{checkingAccount}; + // : When + Customer lena = new Customer(customerName, userName, password, accounts); + String actualName = lena.getCustomerName(); + + // : Then + Assert.assertEquals(customerName, actualName); + + } + @Test + public void setCustomerName() { + // : Given + String customerName = "Liam Becker"; + String userName = "hbecker"; + String password = "zipcode0"; + Account checkingAccount = new Checking(22456, 25631); + Account[] accounts = new Account[]{checkingAccount}; + // : When + Customer hazel = new Customer(customerName, userName, password, accounts); + hazel.setCustomerName("Hazel Becker"); + String expected = "Hazel Becker"; + String actualName = hazel.getCustomerName(); + // : Then + Assert.assertEquals(expected, actualName); + } + + @Test + public void getUserName() { + // : Given + String customerName = "Mike Ninh"; + String userName = "DynoMike"; + String password = "zipcode0"; + Account checkingAccount = new Checking(26226, 12956); + Account[] accounts = new Account[]{checkingAccount}; + // : When + Customer mike = new Customer(customerName, userName, password, accounts); + String actualName = mike.getUserName(); + // : Then + Assert.assertEquals(userName, actualName); + } + + @Test + public void setUserName() { + String customerName = "Ask Ketchum"; + String userName = "WannaPokemonMaster"; + String password = "BeTheVeryBest"; + Account checkingAccount = new Checking(34113, 1000); + Account[] accounts = new Account[]{checkingAccount}; + // : When + Customer ketchumAll = new Customer(customerName, userName, password, accounts); + ketchumAll.setUserName("PokemonMaster"); + String expected = "PokemonMaster"; + String actualName = ketchumAll.getUserName(); + // : Then + Assert.assertEquals(expected, actualName); + } + + @Test + public void getPassWord() { + String customerName = "Tony Stark"; + String userName = "IronMan"; + String password = "zipcode0"; + Account checkingAccount = new Checking(12402, 923132956); + Account[] accounts = new Account[]{checkingAccount}; + // : When + Customer stark = new Customer(customerName, userName, password, accounts); + String actualpassword = stark.getPassword(); + // : Then + Assert.assertEquals(password, actualpassword); + } + + @Test + public void setPassWord() { + String customerName = ""; + String userName = ""; + String password = ""; + Account checkingAccount = new Checking(22456, 25631); + Account[] accounts = new Account[]{checkingAccount}; + // : When + Customer test = new Customer(customerName, userName, password, accounts); + test.setPassword("spotholder"); + String expectedPW = "spotholder"; + String actualPW = test.getPassword(); + // : Then + Assert.assertEquals(expectedPW, actualPW); + } + + @Test + public void getAccountNumber() { + // : Given + String customerName = "Bruce Wayne"; + String userName = "NotBatman"; + String password = "zipcode0"; + Account checkingAccount = new Checking(32563, 915252956); + Account[] accounts = new Account[]{checkingAccount}; + // : When + String account = "32563"; + Customer wayne = new Customer(customerName, userName, password, accounts); + String actualAccount = wayne.getAccountNumber(); + // : Then + Assert.assertEquals(account, actualAccount); + } + + } From 1afca0aadcf3117387d976e70e494e0b4775b678 Mon Sep 17 00:00:00 2001 From: mike Date: Sat, 13 Mar 2021 09:11:56 -0500 Subject: [PATCH 10/35] updated test complete --- src/main/test/java/CustomerTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/test/java/CustomerTest.java b/src/main/test/java/CustomerTest.java index e918107..c51f696 100644 --- a/src/main/test/java/CustomerTest.java +++ b/src/main/test/java/CustomerTest.java @@ -17,13 +17,14 @@ public void customerConstuctor() { String actualName = xiong.getCustomerName(); String actualUserName = xiong.getUserName(); String actualPassword = xiong.getPassword(); - String account = "242341"; + String account = "24231 "; + String actualAccount = xiong.getAccountNumber(); // : Then Assert.assertEquals(customerName, actualName); Assert.assertEquals(userName, actualUserName); Assert.assertEquals(password, actualPassword); - Assert.assertEquals(account, accounts); + Assert.assertEquals(account, actualAccount); } @@ -131,7 +132,7 @@ public void getAccountNumber() { Account checkingAccount = new Checking(32563, 915252956); Account[] accounts = new Account[]{checkingAccount}; // : When - String account = "32563"; + String account = "32563 "; Customer wayne = new Customer(customerName, userName, password, accounts); String actualAccount = wayne.getAccountNumber(); // : Then From 635320642e3b2e7334aabac37743a0c6e35102b8 Mon Sep 17 00:00:00 2001 From: xiong Date: Sat, 13 Mar 2021 09:39:34 -0500 Subject: [PATCH 11/35] moved methods for open/close to Customer class --- src/main/java/Customer.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/Customer.java b/src/main/java/Customer.java index 7b35d6d..9b61fdd 100644 --- a/src/main/java/Customer.java +++ b/src/main/java/Customer.java @@ -44,5 +44,28 @@ public String getAccountNumber() { return accountNumbers; } + public void openCheckingAccount(int accountNumber, double initialDeposit) { + Account newAccount = new Checking(accountNumber, initialDeposit); + accounts.add(newAccount); + } + + public void openSavingsAccount(int accountNumber, double initialDeposit) { + Account newAccount = new Savings(accountNumber, initialDeposit); + accounts.add(newAccount); + } + public void openInvestmentAccount(int accountNumber, double initialDeposit) { + Account newAccount = new Investment(accountNumber, initialDeposit); + accounts.add(newAccount); + } + + public void closeAccount(Integer accountNumber) { + for (int i = 0; i < accounts.size(); i++) { + if (accounts.get(i).getAccountNumber() == accountNumber) { + if (accounts.get(i).getBalance() == 0) { + accounts.remove(i); + } + } + } + } } From 11dfb66c75dc35ea501a7bd583af782785a57d78 Mon Sep 17 00:00:00 2001 From: xiong Date: Sat, 13 Mar 2021 19:08:45 -0500 Subject: [PATCH 12/35] fixed and refactor code --- src/main/java/Account.java | 3 +- src/main/java/Checking.java | 6 +- src/main/java/Customer.java | 23 ++++-- src/main/java/Investment.java | 12 +-- src/main/java/Savings.java | 14 +--- src/main/test/java/CustomerTest.java | 117 ++++++++++++++++++++++++++- 6 files changed, 141 insertions(+), 34 deletions(-) diff --git a/src/main/java/Account.java b/src/main/java/Account.java index 6a39c72..e7349e5 100644 --- a/src/main/java/Account.java +++ b/src/main/java/Account.java @@ -16,7 +16,7 @@ public double getBalance() { } public double withdraw(double amount) { - if (balance > amount && balance - amount >= 0) { + if (balance >= amount) { balance -= amount; } return balance; @@ -26,5 +26,4 @@ public double deposit(double amount) { return balance += amount; } - } diff --git a/src/main/java/Checking.java b/src/main/java/Checking.java index 681e908..53bdee3 100644 --- a/src/main/java/Checking.java +++ b/src/main/java/Checking.java @@ -5,16 +5,14 @@ public Checking(Integer accountNumber, double balance) { } public void transferToSavings(Savings savingsAccount, double transferAmount) { - if (this.getBalance() > transferAmount && this.getBalance() - transferAmount >= 0) { + if (this.getBalance() >= transferAmount) { this.withdraw(transferAmount); savingsAccount.deposit(transferAmount); } - - //return this.getBalance(); } public void transferToInvestment(Investment investmentAccount, double transferAmount) { - if (this.getBalance() > transferAmount && this.getBalance() - transferAmount >= 0) { + if (this.getBalance() >= transferAmount) { this.withdraw(transferAmount); investmentAccount.deposit(transferAmount); } diff --git a/src/main/java/Customer.java b/src/main/java/Customer.java index 9b61fdd..9778ea3 100644 --- a/src/main/java/Customer.java +++ b/src/main/java/Customer.java @@ -6,14 +6,14 @@ public class Customer { private String customerName; private String userName; private String password; - private List accounts = new ArrayList(); + private ArrayList accounts; public Customer(String customerName, String userName, String password, Account[] accounts){ this.customerName = customerName; this.userName = userName; this.password = password; - this.accounts = Arrays.asList(accounts); + this.accounts = new ArrayList(Arrays.asList(accounts)); } public String getCustomerName(){ return this.customerName;} @@ -39,23 +39,32 @@ public void setPassword(String password){ public String getAccountNumber() { String accountNumbers = ""; for(int i = 0; i < accounts.size(); i++) { - accountNumbers += String.format("%s ", accounts.get(i).getAccountNumber()); + accountNumbers += String.format("%s\n", accounts.get(i).getAccountNumber()); } return accountNumbers; } + public Account getAccount(int accountNumber) { + for (Account account : accounts) { + if (account.getAccountNumber() == accountNumber) { + return account; + } + } + return null; + } + public void openCheckingAccount(int accountNumber, double initialDeposit) { - Account newAccount = new Checking(accountNumber, initialDeposit); - accounts.add(newAccount); + Checking newAccount = new Checking(accountNumber, initialDeposit); + accounts.add(newAccount); } public void openSavingsAccount(int accountNumber, double initialDeposit) { - Account newAccount = new Savings(accountNumber, initialDeposit); + Savings newAccount = new Savings(accountNumber, initialDeposit); accounts.add(newAccount); } public void openInvestmentAccount(int accountNumber, double initialDeposit) { - Account newAccount = new Investment(accountNumber, initialDeposit); + Investment newAccount = new Investment(accountNumber, initialDeposit); accounts.add(newAccount); } diff --git a/src/main/java/Investment.java b/src/main/java/Investment.java index eb6d993..d9c72fe 100644 --- a/src/main/java/Investment.java +++ b/src/main/java/Investment.java @@ -4,21 +4,17 @@ public Investment(Integer accountNumber, double balance) { super(accountNumber, balance); } - public double transferToSavings(Savings savingsAccount, double transferAmount) { - if (this.getBalance() > transferAmount && this.getBalance() - transferAmount >= 0) { + public void transferToSavings(Savings savingsAccount, double transferAmount) { + if (this.getBalance() >= transferAmount) { this.withdraw(transferAmount); savingsAccount.deposit(transferAmount); } - - return this.getBalance(); } - public double transferToChecking(Checking checkingAccount, double transferAmount) { - if (this.getBalance() > transferAmount && this.getBalance() - transferAmount >= 0) { + public void transferToChecking(Checking checkingAccount, double transferAmount) { + if (this.getBalance() >= transferAmount) { this.withdraw(transferAmount); checkingAccount.deposit(transferAmount); } - - return this.getBalance(); } } diff --git a/src/main/java/Savings.java b/src/main/java/Savings.java index d1eb5ee..e411110 100644 --- a/src/main/java/Savings.java +++ b/src/main/java/Savings.java @@ -4,23 +4,17 @@ public Savings(Integer accountNumber, double balance) { super(accountNumber, balance); } - public double transferToChecking(Checking checkingAccount, double transferAmount) { - if (this.getBalance() > transferAmount && this.getBalance() - transferAmount >= 0) { + public void transferToChecking(Checking checkingAccount, double transferAmount) { + if (this.getBalance() >= transferAmount) { this.withdraw(transferAmount); checkingAccount.deposit(transferAmount); } - else System.out.println("Non sufficient funds"); - - return this.getBalance(); } - public double transferToInvestment(Investment investmentAccount, double transferAmount) { - if (this.getBalance() > transferAmount && this.getBalance() - transferAmount >= 0) { + public void transferToInvestment(Investment investmentAccount, double transferAmount) { + if (this.getBalance() >= transferAmount) { this.withdraw(transferAmount); investmentAccount.deposit(transferAmount); } - else System.out.println("Non sufficient funds"); - - return this.getBalance(); } } diff --git a/src/main/test/java/CustomerTest.java b/src/main/test/java/CustomerTest.java index c51f696..39f2beb 100644 --- a/src/main/test/java/CustomerTest.java +++ b/src/main/test/java/CustomerTest.java @@ -17,7 +17,7 @@ public void customerConstuctor() { String actualName = xiong.getCustomerName(); String actualUserName = xiong.getUserName(); String actualPassword = xiong.getPassword(); - String account = "24231 "; + String account = "24231\n"; String actualAccount = xiong.getAccountNumber(); // : Then @@ -130,13 +130,124 @@ public void getAccountNumber() { String userName = "NotBatman"; String password = "zipcode0"; Account checkingAccount = new Checking(32563, 915252956); - Account[] accounts = new Account[]{checkingAccount}; + Account savingsAccount = new Savings(992223, 750); + Account investAccount = new Investment(111, 50000); + Account[] accounts = new Account[]{checkingAccount, savingsAccount, investAccount}; // : When - String account = "32563 "; + String account = "32563\n" + "992223\n" + "111\n"; Customer wayne = new Customer(customerName, userName, password, accounts); String actualAccount = wayne.getAccountNumber(); + + System.out.println(actualAccount); // : Then Assert.assertEquals(account, actualAccount); } + @Test + public void testOpenCheckingAccount() { + // : Given + String customerName = "Bruce Wayne"; + String userName = "NotBatman"; + String password = "zipcode0"; + Account checkingAccount = new Checking(32563, 915252956); + Account savingsAccount = new Savings(992223, 750); + Account investAccount = new Investment(111, 50000); + Account[] accounts = new Account[]{checkingAccount, savingsAccount, investAccount}; + // : When + String account = "32563\n" + "992223\n" + "111\n" + "69420\n"; + Customer wayne = new Customer(customerName, userName, password, accounts); + wayne.openCheckingAccount(69420, 50000); + String actualAccount = wayne.getAccountNumber(); + + System.out.println(actualAccount); + // : Then + Assert.assertEquals(account, actualAccount); + } + + @Test + public void testOpenSavingsAccount() { + // : Given + String customerName = "Bruce Wayne"; + String userName = "NotBatman"; + String password = "zipcode0"; + Account checkingAccount = new Checking(32563, 915252956); + Account savingsAccount = new Savings(992223, 750); + Account investAccount = new Investment(111, 50000); + Account[] accounts = new Account[]{checkingAccount, savingsAccount, investAccount}; + // : When + String account = "32563\n" + "992223\n" + "111\n" + "6969\n"; + Customer wayne = new Customer(customerName, userName, password, accounts); + wayne.openSavingsAccount(6969, 50000); + String actualAccount = wayne.getAccountNumber(); + + System.out.println(actualAccount); + // : Then + Assert.assertEquals(account, actualAccount); + } + + @Test + public void testOpenInvestmentAccount() { + // : Given + String customerName = "Bruce Wayne"; + String userName = "NotBatman"; + String password = "zipcode0"; + Account checkingAccount = new Checking(32563, 915252956); + Account savingsAccount = new Savings(992223, 750); + Account investAccount = new Investment(111, 50000); + Account[] accounts = new Account[]{checkingAccount, savingsAccount, investAccount}; + // : When + String account = "32563\n" + "992223\n" + "111\n" + "420420\n"; + Customer wayne = new Customer(customerName, userName, password, accounts); + wayne.openInvestmentAccount(420420, 50000); + String actualAccount = wayne.getAccountNumber(); + + System.out.println(actualAccount); + // : Then + Assert.assertEquals(account, actualAccount); + } + + @Test + public void testCloseAccountWithBalance() { + // : Given + String customerName = "Bruce Wayne"; + String userName = "NotBatman"; + String password = "zipcode0"; + Account checkingAccount = new Checking(32563, 915252956); + Account savingsAccount = new Savings(992223, 750); + Account investAccount = new Investment(111, 50000); + Account[] accounts = new Account[]{checkingAccount, savingsAccount, investAccount}; + // : When + String account = "32563\n" + "992223\n" + "111\n"; + Customer wayne = new Customer(customerName, userName, password, accounts); + wayne.getAccount(111).withdraw(10000); + wayne.closeAccount(111); + String actualAccount = wayne.getAccountNumber(); + + System.out.println(actualAccount); + // : Then + Assert.assertEquals(account, actualAccount); } + + @Test + public void testCloseAccountWithNoBalance() { + // : Given + String customerName = "Bruce Wayne"; + String userName = "NotBatman"; + String password = "zipcode0"; + Account checkingAccount = new Checking(32563, 915252956); + Account savingsAccount = new Savings(992223, 750); + Account investAccount = new Investment(111, 50000); + Account[] accounts = new Account[]{checkingAccount, savingsAccount, investAccount}; + // : When + String account = "32563\n" + "992223\n"; + Customer wayne = new Customer(customerName, userName, password, accounts); + wayne.getAccount(111).withdraw(50000); + wayne.closeAccount(111); + String actualAccount = wayne.getAccountNumber(); + + System.out.println(actualAccount); + // : Then + Assert.assertEquals(account, actualAccount); + } + +} From 86a0e67ee8f3bd71d0b047d5e5ff41ad00e33973 Mon Sep 17 00:00:00 2001 From: hazel Date: Sat, 13 Mar 2021 12:52:56 -0500 Subject: [PATCH 13/35] Minor refinement of display --- src/main/java/Display.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/Display.java b/src/main/java/Display.java index 0be6254..d340ced 100644 --- a/src/main/java/Display.java +++ b/src/main/java/Display.java @@ -10,24 +10,24 @@ public Display(){ this.transactionHistory = ""; } - public String getCurrentDisplay() { - return currentDisplay; + public void printCurrentDisplay() { + System.out.println(currentDisplay); } public void setCurrentDisplay(String currentDisplay) { this.currentDisplay = currentDisplay; } - public String getMenu() { - return menu; + public void printMenu() { + System.out.println(menu); } public void setMenu(String menu) { this.menu = menu; } - public String getTransactionHistory() { - return transactionHistory; + public void printTransactionHistory() { + System.out.println(transactionHistory); } public void setTransactionHistory(String transactionHistory) { From f802066adfaeae5aefe051341e6e68d7e9d54ac4 Mon Sep 17 00:00:00 2001 From: hazel Date: Sat, 13 Mar 2021 13:18:56 -0500 Subject: [PATCH 14/35] Split display into another class, workflow --- src/main/java/Console.java | 2 +- src/main/java/Display.java | 29 +++++++++++++++++++++++++++++ src/main/java/Workflow.java | 22 ++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/main/java/Workflow.java diff --git a/src/main/java/Console.java b/src/main/java/Console.java index 3a9ba78..7389a3b 100644 --- a/src/main/java/Console.java +++ b/src/main/java/Console.java @@ -14,7 +14,7 @@ public String getStringInput(String prompt) { Scanner scanner = new Scanner(System.in); println(prompt); String userInput = scanner.nextLine(); - return userInput; + return userInput.toLowerCase(); } diff --git a/src/main/java/Display.java b/src/main/java/Display.java index d340ced..bee143c 100644 --- a/src/main/java/Display.java +++ b/src/main/java/Display.java @@ -10,6 +10,8 @@ public Display(){ this.transactionHistory = ""; } + /* *****Getters and setters***** */ + public void printCurrentDisplay() { System.out.println(currentDisplay); } @@ -18,6 +20,14 @@ public void setCurrentDisplay(String currentDisplay) { this.currentDisplay = currentDisplay; } + //set AND print in one + public void currentDisplaySP(String currentDisplay){ + this.setCurrentDisplay(currentDisplay); + this.printCurrentDisplay(); + } + + + public void printMenu() { System.out.println(menu); } @@ -26,6 +36,14 @@ public void setMenu(String menu) { this.menu = menu; } + //set AND print in one + public void menuSP(String menu){ + this.setMenu(menu); + this.printMenu(); + } + + + public void printTransactionHistory() { System.out.println(transactionHistory); } @@ -33,4 +51,15 @@ public void printTransactionHistory() { public void setTransactionHistory(String transactionHistory) { this.transactionHistory = transactionHistory; } + + } + + + + + + + + + diff --git a/src/main/java/Workflow.java b/src/main/java/Workflow.java new file mode 100644 index 0000000..f578bd5 --- /dev/null +++ b/src/main/java/Workflow.java @@ -0,0 +1,22 @@ +public class Workflow { + + Display d; + Console c; + + public Workflow(){ + d = new Display(); + c = new Console(); + } + + public void errorSP(){ + d.currentDisplaySP("Improper input. Please reread instructions."); + } + + public Integer initialWelcomeSP(){ + d.currentDisplaySP("Welcome to the ATM! Are you a new or returning user?"); + return c.getIntegerInput("Enter 1 for new, 2 for returning"); + } + + + +} From 078fa02294e08457f9144a5aff61b0ce74afb161 Mon Sep 17 00:00:00 2001 From: hazel Date: Sat, 13 Mar 2021 13:29:47 -0500 Subject: [PATCH 15/35] More work on workflow --- src/main/java/Console.java | 8 +++++++- src/main/java/Display.java | 8 ++++---- src/main/java/Workflow.java | 28 +++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/main/java/Console.java b/src/main/java/Console.java index 7389a3b..d74f765 100644 --- a/src/main/java/Console.java +++ b/src/main/java/Console.java @@ -14,8 +14,14 @@ public String getStringInput(String prompt) { Scanner scanner = new Scanner(System.in); println(prompt); String userInput = scanner.nextLine(); - return userInput.toLowerCase(); + return userInput; + } + public String getStringInputNotCaseSensitive(String prompt) { + Scanner scanner = new Scanner(System.in); + println(prompt); + String userInput = scanner.nextLine(); + return userInput.toLowerCase(); } public Integer getIntegerInput(String prompt) { diff --git a/src/main/java/Display.java b/src/main/java/Display.java index bee143c..748d5cc 100644 --- a/src/main/java/Display.java +++ b/src/main/java/Display.java @@ -1,12 +1,12 @@ public class Display { String currentDisplay; - String menu; + //String menu; String transactionHistory; public Display(){ this.currentDisplay = ""; - this.menu = ""; + //this.menu = ""; this.transactionHistory = ""; } @@ -28,7 +28,7 @@ public void currentDisplaySP(String currentDisplay){ - public void printMenu() { + /*public void printMenu() { System.out.println(menu); } @@ -40,7 +40,7 @@ public void setMenu(String menu) { public void menuSP(String menu){ this.setMenu(menu); this.printMenu(); - } + }*/ diff --git a/src/main/java/Workflow.java b/src/main/java/Workflow.java index f578bd5..a4925f6 100644 --- a/src/main/java/Workflow.java +++ b/src/main/java/Workflow.java @@ -14,9 +14,35 @@ public void errorSP(){ public Integer initialWelcomeSP(){ d.currentDisplaySP("Welcome to the ATM! Are you a new or returning user?"); - return c.getIntegerInput("Enter 1 for new, 2 for returning"); + return c.getIntegerInput("Enter 1 for new, 2 for returning:"); } + public void newUserSP(){ + d.currentDisplaySP("Input your username, then password twice, or type one lowercase x now to cancel."); + } + + public void passwordMismatchSP(){ + d.currentDisplaySP("Passwords do not match. Please try again."); + } + + public void returningUserSP(){ + d.currentDisplaySP("Input your username, then password, or type one lowercase x now to cancel."); + } + + public String getUserSP(){ + return c.getStringInput("Enter username:"); + } + + public String getaPassSP(){ + return c.getStringInput("Enter password:"); + } + + + + public void mainMenuSP(Customer customer){ + + } + } From 76ab0f9cef17b3153dbc9b58df2be77d461a9b13 Mon Sep 17 00:00:00 2001 From: hazel Date: Sat, 13 Mar 2021 13:54:31 -0500 Subject: [PATCH 16/35] Checkpointing --- src/main/java/Main.java | 4 +++- src/main/java/Workflow.java | 43 ++++++++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 1dbc0cb..7d4fd36 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -4,6 +4,8 @@ public class Main { public static void main(String[] args){ - + Workflow w = new Workflow(); + Customer person = new Customer("Hazel", "12345", 67890); + w.mainMenuSP(person); } } diff --git a/src/main/java/Workflow.java b/src/main/java/Workflow.java index a4925f6..f7bbf1a 100644 --- a/src/main/java/Workflow.java +++ b/src/main/java/Workflow.java @@ -9,12 +9,15 @@ public Workflow(){ } public void errorSP(){ - d.currentDisplaySP("Improper input. Please reread instructions."); + d.currentDisplaySP("\nImproper input. Please reread instructions.\n"); } - public Integer initialWelcomeSP(){ - d.currentDisplaySP("Welcome to the ATM! Are you a new or returning user?"); - return c.getIntegerInput("Enter 1 for new, 2 for returning:"); + public void initialWelcomeSP(){ + d.currentDisplaySP("Welcome to the ATM! Are you a new or returning user?\nEnter 1 for new, 2 for returning."); + } + + public Integer getInput(){ + return c.getIntegerInput("Enter your input:"); } @@ -35,14 +38,44 @@ public String getUserSP(){ return c.getStringInput("Enter username:"); } - public String getaPassSP(){ + public String getPassSP(){ return c.getStringInput("Enter password:"); } public void mainMenuSP(Customer customer){ + d.currentDisplaySP("Welcome, " + customer.getUserName() + "! What do you want to do?\nEnter 1 to check balance\t\t\t\tEnter 2 to transfer\nEnter 3 to withdraw\t\t\t\t\t\tEnter 4 to deposit\nEnter 5 to open a new account\t\t\tEnter 6 to close an account\nEnter 7 to print transaction history\tEnter 8 to log out"); + } + + + + public String enterAccount(){ + return c.getStringInputNotCaseSensitive("Enter an account:"); + } + + public void checkPromptSP(){ + d.currentDisplaySP("What account do you want to check?"); + } + + public void withdrawPromptSP(){ + d.currentDisplaySP("What account do you want to withdraw from?"); + } + + public void depositPromptSP(){ + d.currentDisplaySP("What account do you want to deposit into?"); + } + + public void transferPromptSP(){ + d.currentDisplaySP("What accounts do you want to transfer from and to?"); + } + + public String openPrompt(){ + return c.getStringInputNotCaseSensitive("What kind of account do you want to open?"); + } + public void closePromptSP(){ + d.currentDisplaySP("What account do you want to close?\nNOTE: The account must be empty."); } } From cc2f1a3e1443440362115c4eedef3525a43d55e8 Mon Sep 17 00:00:00 2001 From: hazel Date: Sat, 13 Mar 2021 14:04:56 -0500 Subject: [PATCH 17/35] Checkpointing --- src/main/java/Workflow.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/Workflow.java b/src/main/java/Workflow.java index f7bbf1a..3e9e853 100644 --- a/src/main/java/Workflow.java +++ b/src/main/java/Workflow.java @@ -2,10 +2,12 @@ public class Workflow { Display d; Console c; + String history; public Workflow(){ d = new Display(); c = new Console(); + history = ""; } public void errorSP(){ @@ -58,6 +60,12 @@ public void checkPromptSP(){ d.currentDisplaySP("What account do you want to check?"); } + public void checkResultSP(Account account){ + d.currentDisplaySP("Your account's current balance is " + account.getBalance()); + } + + + public void withdrawPromptSP(){ d.currentDisplaySP("What account do you want to withdraw from?"); } @@ -70,6 +78,12 @@ public void transferPromptSP(){ d.currentDisplaySP("What accounts do you want to transfer from and to?"); } + public void completeResultSP(){ + d.currentDisplaySP("Action performed successfully."); + } + + + public String openPrompt(){ return c.getStringInputNotCaseSensitive("What kind of account do you want to open?"); } From 219c957f04774c95f93caff8d9c05ed3221f47c8 Mon Sep 17 00:00:00 2001 From: hazel Date: Sat, 13 Mar 2021 17:18:30 -0500 Subject: [PATCH 18/35] Filled out workflow --- src/main/java/Display.java | 4 ++++ src/main/java/Main.java | 4 +--- src/main/java/Workflow.java | 37 +++++++++++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/main/java/Display.java b/src/main/java/Display.java index 748d5cc..cac5e09 100644 --- a/src/main/java/Display.java +++ b/src/main/java/Display.java @@ -52,6 +52,10 @@ public void setTransactionHistory(String transactionHistory) { this.transactionHistory = transactionHistory; } + public void addToTransactionHistory(String snippet){ + this.transactionHistory = this.transactionHistory + snippet; + } + } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 7d4fd36..05e41a9 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -4,8 +4,6 @@ public class Main { public static void main(String[] args){ - Workflow w = new Workflow(); - Customer person = new Customer("Hazel", "12345", 67890); - w.mainMenuSP(person); + } } diff --git a/src/main/java/Workflow.java b/src/main/java/Workflow.java index 3e9e853..a8630cd 100644 --- a/src/main/java/Workflow.java +++ b/src/main/java/Workflow.java @@ -2,12 +2,14 @@ public class Workflow { Display d; Console c; - String history; + String lastAction; + Integer lastAmount; public Workflow(){ d = new Display(); c = new Console(); - history = ""; + lastAction = ""; + lastAmount = 0; } public void errorSP(){ @@ -37,7 +39,9 @@ public void returningUserSP(){ } public String getUserSP(){ - return c.getStringInput("Enter username:"); + String middleMan = c.getStringInput("Enter username:"); + d.setTransactionHistory("History of user " + middleMan); + return middleMan; } public String getPassSP(){ @@ -68,18 +72,32 @@ public void checkResultSP(Account account){ public void withdrawPromptSP(){ d.currentDisplaySP("What account do you want to withdraw from?"); + lastAction = " withdrawn from "; } public void depositPromptSP(){ d.currentDisplaySP("What account do you want to deposit into?"); + lastAction = " deposited into "; } public void transferPromptSP(){ d.currentDisplaySP("What accounts do you want to transfer from and to?"); + lastAction = " transferred to "; } - public void completeResultSP(){ + public Integer amountPromptSP(){ + lastAmount = c.getIntegerInput("How much?"); + return lastAmount; + } + + public void completeResultSP(Account account){ + d.currentDisplaySP("Action performed successfully."); + d.addToTransactionHistory("$" + lastAmount + lastAction + "account #" + account.getAccountNumber()); + } + + public void completeResultSP(Account account1, Account account2){ d.currentDisplaySP("Action performed successfully."); + d.addToTransactionHistory("$" + lastAmount + lastAction + "account #" + account1.getAccountNumber() + " to account #" + account2.getAccountNumber()); } @@ -92,4 +110,15 @@ public void closePromptSP(){ d.currentDisplaySP("What account do you want to close?\nNOTE: The account must be empty."); } + + + //history stuff? + + + + public void logOutSP(){ + d.currentDisplaySP("Thank you for your business."); + d.setTransactionHistory(""); + } + } From 621a0834ded6ae0ebf85e516eac500b2e2d20cfc Mon Sep 17 00:00:00 2001 From: hazel Date: Sat, 13 Mar 2021 18:07:59 -0500 Subject: [PATCH 19/35] Manual update --- src/main/java/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 05e41a9..1dbc0cb 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -4,6 +4,6 @@ public class Main { public static void main(String[] args){ - + } } From 6abeec9a8825841d31d7d57e7d4ec764ac058354 Mon Sep 17 00:00:00 2001 From: hazel Date: Sat, 13 Mar 2021 19:08:28 -0500 Subject: [PATCH 20/35] Checkpointing for pull. Began workflow test --- src/main/java/Display.java | 18 ------- src/main/java/Main.java | 2 +- src/main/java/Workflow.java | 16 +++---- src/main/test/AccountTest.java | 83 --------------------------------- src/main/test/WorkflowTest.java | 22 +++++++++ 5 files changed, 31 insertions(+), 110 deletions(-) delete mode 100644 src/main/test/AccountTest.java create mode 100644 src/main/test/WorkflowTest.java diff --git a/src/main/java/Display.java b/src/main/java/Display.java index cac5e09..0e6126e 100644 --- a/src/main/java/Display.java +++ b/src/main/java/Display.java @@ -1,12 +1,10 @@ public class Display { String currentDisplay; - //String menu; String transactionHistory; public Display(){ this.currentDisplay = ""; - //this.menu = ""; this.transactionHistory = ""; } @@ -28,22 +26,6 @@ public void currentDisplaySP(String currentDisplay){ - /*public void printMenu() { - System.out.println(menu); - } - - public void setMenu(String menu) { - this.menu = menu; - } - - //set AND print in one - public void menuSP(String menu){ - this.setMenu(menu); - this.printMenu(); - }*/ - - - public void printTransactionHistory() { System.out.println(transactionHistory); } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 1dbc0cb..05e41a9 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -4,6 +4,6 @@ public class Main { public static void main(String[] args){ - + } } diff --git a/src/main/java/Workflow.java b/src/main/java/Workflow.java index a8630cd..3f83385 100644 --- a/src/main/java/Workflow.java +++ b/src/main/java/Workflow.java @@ -40,7 +40,7 @@ public void returningUserSP(){ public String getUserSP(){ String middleMan = c.getStringInput("Enter username:"); - d.setTransactionHistory("History of user " + middleMan); + d.setTransactionHistory("History of user " + middleMan + "\n"); return middleMan; } @@ -51,7 +51,7 @@ public String getPassSP(){ public void mainMenuSP(Customer customer){ - d.currentDisplaySP("Welcome, " + customer.getUserName() + "! What do you want to do?\nEnter 1 to check balance\t\t\t\tEnter 2 to transfer\nEnter 3 to withdraw\t\t\t\t\t\tEnter 4 to deposit\nEnter 5 to open a new account\t\t\tEnter 6 to close an account\nEnter 7 to print transaction history\tEnter 8 to log out"); + d.currentDisplaySP("Welcome, " + customer.getCustomerName() + "! What do you want to do?\nEnter 1 to check balance\t\t\t\tEnter 2 to transfer\nEnter 3 to withdraw\t\t\t\t\t\tEnter 4 to deposit\nEnter 5 to open a new account\t\t\tEnter 6 to close an account\nEnter 7 to print transaction history\tEnter 8 to log out"); } @@ -91,13 +91,13 @@ public Integer amountPromptSP(){ } public void completeResultSP(Account account){ - d.currentDisplaySP("Action performed successfully."); + d.currentDisplaySP("Action performed successfully.\n"); d.addToTransactionHistory("$" + lastAmount + lastAction + "account #" + account.getAccountNumber()); } public void completeResultSP(Account account1, Account account2){ - d.currentDisplaySP("Action performed successfully."); - d.addToTransactionHistory("$" + lastAmount + lastAction + "account #" + account1.getAccountNumber() + " to account #" + account2.getAccountNumber()); + d.currentDisplaySP("Action performed successfully.\n"); + d.addToTransactionHistory("$" + lastAmount + lastAction + "account #" + account1.getAccountNumber() + " to account #" + account2.getAccountNumber() + "\n"); } @@ -110,9 +110,9 @@ public void closePromptSP(){ d.currentDisplaySP("What account do you want to close?\nNOTE: The account must be empty."); } - - - //history stuff? + public void printHistory(){ + d.printTransactionHistory(); + } diff --git a/src/main/test/AccountTest.java b/src/main/test/AccountTest.java deleted file mode 100644 index cbea4ad..0000000 --- a/src/main/test/AccountTest.java +++ /dev/null @@ -1,83 +0,0 @@ - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.junit.Assert.assertEquals; - - -// Test the expected Account class from ATM. -public class AccountTest { - - @Test - public void testA0() { - Account a = new Account(0.0); - assertEquals(0.0, a.balance(), 0.0001); - } - - @Test - public void testA00() { - Account a = new Account(10.0); - assertEquals(10.0, a.balance(), 0.0001); - } - - @Test - public void testA01() { - Account a = new Account(0.0); - assertEquals(true, a.closeAccount()); - } - - @Test - public void testA02() { - Account a = new Account(10.0); - assertEquals(false, a.closeAccount()); - } - - @Test - public void testA1() { - Account a = new Account(0.0); - a.deposit(100.0); - assertEquals(100.0, a.balance(), 0.0001); - } - - @Test - public void testA2() { - Account a = new Account(10.0); - a.deposit(100.0); - assertEquals(110.0, a.balance(), 0.0001); - } - - @Test - public void testA3() { - Account a = new Account(200.0); - Double actual = a.withdraw(100.0); - assertEquals(100.0, actual, 0.0001); - } - - @Test - public void testA4() { - Account a = new Account(0.0); - Double actual = a.withdraw(1.0); - assertEquals(0.0, actual, 0.0001); - } - - @Test - public void testA5() { - Account a = new Account(10.0); - Account b = new Account(0.0); - a.transfer(b, 10.0); - assertEquals(0.0, a.balance(), 0.0001); - assertEquals(10.0, b.balance(), 0.0001); - } - - @Test - public void testA6() { - Account a = new Account(10.0); - Account b = new Account(0.0); - a.transfer(b, 100.0); // nothing should happen - assertEquals(10.0, a.balance(), 0.0001); - assertEquals(0.0, b.balance(), 0.0001); - } - - -} diff --git a/src/main/test/WorkflowTest.java b/src/main/test/WorkflowTest.java new file mode 100644 index 0000000..90c08c7 --- /dev/null +++ b/src/main/test/WorkflowTest.java @@ -0,0 +1,22 @@ +import org.junit.Test; + +public class WorkflowTest { + + @Test + public void Test1() { + + Workflow w = new Workflow(); + + Account acct = new Savings(12, 34.0); + Account[] accts = new Account[1]; + accts[0] = acct; + Customer customer = new Customer("Hazel", "HD", "45", accts); + + String user = w.getUserSP(); + w.mainMenuSP(customer); + w.withdrawPromptSP(); + Integer int1 = w.amountPromptSP(); + w.completeResultSP(accts[0]); + w.printHistory(); + } +} From 7e0fbd59290e7c3c2c235ff2cfc4c179422555ae Mon Sep 17 00:00:00 2001 From: hazel Date: Sat, 13 Mar 2021 19:16:29 -0500 Subject: [PATCH 21/35] Fighting git --- src/main/java/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 05e41a9..1dbc0cb 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -4,6 +4,6 @@ public class Main { public static void main(String[] args){ - + } } From 36861cb85fccf20d53781593ab63a689fa1a5ed5 Mon Sep 17 00:00:00 2001 From: xiong Date: Sat, 13 Mar 2021 19:41:34 -0500 Subject: [PATCH 22/35] merged progress --- src/main/test/java/InvestmentTest.java | 52 ++++++++++++++--- src/main/test/java/SavingsTest.java | 78 +++++++++++++++++++------- 2 files changed, 100 insertions(+), 30 deletions(-) diff --git a/src/main/test/java/InvestmentTest.java b/src/main/test/java/InvestmentTest.java index 21f4f19..514e07b 100644 --- a/src/main/test/java/InvestmentTest.java +++ b/src/main/test/java/InvestmentTest.java @@ -4,11 +4,11 @@ public class InvestmentTest { @Test - public void testConstructor(){ + public void testConstructor() { // : Given -Integer expectedAccountNumber = 777777777; -Double expectedBalance = 1200.0; -Investment investmentZero=new Investment(expectedAccountNumber,expectedBalance); + Integer expectedAccountNumber = 777777777; + Double expectedBalance = 1200.0; + Investment investmentZero=new Investment(expectedAccountNumber,expectedBalance); // : When @@ -21,7 +21,41 @@ public void testConstructor(){ } @Test - public void testTransferToSavings(){ + public void testDepositToInvestment() { + // : Given + Integer investementAccountNumber = 888888888; + double investmentAccountBalance = 9000.0; + Investment investmentZero=new Investment(investementAccountNumber,investmentAccountBalance); + + // : When + investmentZero.deposit(1000.0); + double expectedInvestmentAccountBalance=10000.0; + double actualInvestmentAccountBalance=investmentZero.getBalance(); + System.out.println(actualInvestmentAccountBalance); + + // : Then + Assert.assertEquals(expectedInvestmentAccountBalance,actualInvestmentAccountBalance, 0.000001); + } + + @Test + public void testWithdrawFromInvestment() { + // : Given + Integer investementAccountNumber = 888888888; + double investmentAccountBalance = 9000.0; + Investment investmentZero=new Investment(investementAccountNumber,investmentAccountBalance); + + // : When + investmentZero.withdraw(2000.0); + double expectedInvestmentAccountBalance=7000.0; + double actualInvestmentAccountBalance=investmentZero.getBalance(); + System.out.println(actualInvestmentAccountBalance); + + // : Then + Assert.assertEquals(expectedInvestmentAccountBalance,actualInvestmentAccountBalance, 0.00001); + } + + @Test + public void testTransferToSavings() { // : Given Integer investementAccountNumber = 777777777; double investmentAccountBalance = 12000.0; @@ -29,6 +63,7 @@ public void testTransferToSavings(){ double savingsAccountBalance=7000.0; Investment investmentZero=new Investment(investementAccountNumber,investmentAccountBalance); Savings savingsZero=new Savings(savingsAccountNumber,savingsAccountBalance); + // : When double transferAmountToSaving=3000.0; double expectedInvestmentAccountBalance=9000.0; @@ -43,10 +78,10 @@ public void testTransferToSavings(){ // : Then Assert.assertEquals(expectedInvestmentAccountBalance,actualInvestmentAccountBalance,0.0000001); Assert.assertEquals(expectedSavingsAccountBalance,actualSavigsAccountBalance, 0.000001); - } + @Test - public void testTransferToChecking(){ + public void testTransferToChecking() { // : Given Integer investementAccountNumber = 888888888; double investmentAccountBalance = 9000.0; @@ -69,6 +104,5 @@ public void testTransferToChecking(){ // : Then Assert.assertEquals(expectedInvestmentAccountBalance,actualInvestmentAccountBalance,0.0000001); Assert.assertEquals(expectedCheckingAccountBalance,actualCheckingAccountBalance, 0.000001); - -} + } } \ No newline at end of file diff --git a/src/main/test/java/SavingsTest.java b/src/main/test/java/SavingsTest.java index d60fddb..dba9eb1 100644 --- a/src/main/test/java/SavingsTest.java +++ b/src/main/test/java/SavingsTest.java @@ -3,24 +3,59 @@ import org.junit.Test; public class SavingsTest { -@Test - -// : Given - public void testSavingsAccount(){ - Integer savingsAccountNumber=9999999; - double savingsAccountBalance=1300.0; - Savings savingsZero=new Savings(savingsAccountNumber,savingsAccountBalance); -// : When - - Integer actualSavingsAccountNumber=savingsZero.getAccountNumber(); - double actualSavingsAccountBalance=savingsZero.getBalance(); - -// : Then - Assert.assertEquals(savingsAccountNumber,actualSavingsAccountNumber, 0.00001); - Assert.assertEquals(savingsAccountBalance,actualSavingsAccountBalance, 0.00001); -} -@Test -public void testTransferToCheckingAccount(){ + + @Test + public void testSavingsAccount() { + // : Given + Integer savingsAccountNumber=9999999; + double savingsAccountBalance=1300.0; + Savings savingsZero=new Savings(savingsAccountNumber,savingsAccountBalance); + // : When + + Integer actualSavingsAccountNumber=savingsZero.getAccountNumber(); + double actualSavingsAccountBalance=savingsZero.getBalance(); + + // : Then + Assert.assertEquals(savingsAccountNumber,actualSavingsAccountNumber, 0.00001); + Assert.assertEquals(savingsAccountBalance,actualSavingsAccountBalance, 0.00001); + } + + @Test + public void testDepositToSavings() { + // : Given + Integer savingsAccountNumber = 888888888; + double savingsAccountBalance = 7000.0; + Savings savingsZero=new Savings(savingsAccountNumber,savingsAccountBalance); + + // : When + savingsZero.deposit(100.0); + double expectedSavingsAccountBalance=7100.0; + double actualSavingsAccountBalance=savingsZero.getBalance(); + System.out.println(actualSavingsAccountBalance); + + // : Then + Assert.assertEquals(expectedSavingsAccountBalance,actualSavingsAccountBalance, 0.000001); + } + + @Test + public void testWithdrawFromSavings() { + // : Given + Integer savingsAccountNumber = 888888888; + double savingsAccountBalance = 9000.0; + Savings savingsZero=new Savings(savingsAccountNumber,savingsAccountBalance); + + // : When + savingsZero.withdraw(6000.0); + double expectedSavingsAccountBalance=3000.0; + double actualSavingsAccountBalance=savingsZero.getBalance(); + System.out.println(actualSavingsAccountBalance); + + // : Then + Assert.assertEquals(expectedSavingsAccountBalance, actualSavingsAccountBalance,0.00001); + } + + @Test + public void testTransferToCheckingAccount() { // : Given Integer savingsAccountNumber = 343234321; double savingsAccountBalance = 0.0; @@ -28,11 +63,12 @@ public void testTransferToCheckingAccount(){ double checkingAccountBalance=8000.0; Checking checkingZero=new Checking(checkingAccountNumber,checkingAccountBalance); Savings savingsZero=new Savings(savingsAccountNumber,savingsAccountBalance); + // : When double transferAmountToChecking=3000.0; double expectedCheckingAccountBalance=8000.0; double expectedSavingsAccountBalance=0.0; - savingsZero.transferToChecking(checkingZero,transferAmountToChecking); + savingsZero.transferToChecking(checkingZero,transferAmountToChecking); double actualCheckingAccountBalance=checkingZero.getBalance(); double actualSavigsAccountBalance=savingsZero.getBalance(); @@ -44,8 +80,9 @@ public void testTransferToCheckingAccount(){ Assert.assertEquals(expectedSavingsAccountBalance,actualSavigsAccountBalance, 0.000001); } + @Test - public void testTransferToInvestment(){ + public void testTransferToInvestment() { // : Given Integer savingsAccountNumber = 7777777; double savingsAccountBalance = 6000.0; @@ -69,6 +106,5 @@ public void testTransferToInvestment(){ // : Then Assert.assertEquals(expectedInvestmentAccountBalance,actualInvestmentAccountBalance,0.0000001); Assert.assertEquals(expectedSavingsAccountBalance,actualSavingsAccountBalance, 0.000001); - } } \ No newline at end of file From d1acf684714609bbe0070572111250bfee587415 Mon Sep 17 00:00:00 2001 From: hazel Date: Sat, 13 Mar 2021 20:33:02 -0500 Subject: [PATCH 23/35] Shell for engine written out --- src/main/java/Main.java | 117 ++++++++++++++++++++++++++++++++ src/main/java/Workflow.java | 27 ++++++-- src/main/test/WorkflowTest.java | 2 +- 3 files changed, 140 insertions(+), 6 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 1dbc0cb..45025f8 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -4,6 +4,123 @@ public class Main { public static void main(String[] args){ + Workflow w = new Workflow(); + Account acct = new Savings(12, 34.0); + Account[] accts = new Account[1]; + accts[0] = acct; + Customer customer = new Customer("Hazel", "HD", "45", accts); + + String user = w.getUserSP(); + w.mainMenuSP(customer); + w.withdrawPromptSP(); + Double dub1 = w.amountPromptSP(); + w.completeResultSP(accts[0]); + w.printHistory(); } + + public void runEngine(){ + Workflow screen = new Workflow(); + + Account acct = new Savings(12, 34.0); + Account[] accts = new Account[1]; + accts[0] = acct; + Customer customer = new Customer("Hazel", "HD", "45", accts); + + //Starting screen + screen.initialWelcomeSP(); + //1 for new user, 2 for returning. this /just/ takes the number tho + screen.getInput(); + + //path 1 + //prompts new user for the necessary info + //name + screen.getNameSP(); + //username + screen.getUserSP(); + //enter password twice. check to see if they match + screen.getPassSP(); + screen.getPassSP(); + //initial deposit + screen.initialAccountOpen(); + + //path 2 + //prompts returning user for the necessary info + //username + screen.getUserSP(); + //password, in while loop, which will kick user out if they fail three times + screen.getPassSP(); + + + + //after the user has either been made or logged in we print the main menu + screen.mainMenuSP(customer); + + //switch statement for each option on the main menu + + //1 + //prints out "Which acct?" + screen.checkPromptSP(); + //The user enters which acct type + screen.enterAccount(); + //Depending on which acct type they enter, this checks the balance of that account + screen.checkResultSP(accts[0]); + + //2 + //prints out "Which acct?" + screen.transferPromptSP(); + //The user enters "from", then "to" + screen.enterAccount(); + screen.enterAccount(); + //there needs to be code in here that actually transfers the money + //print out "action performed successfully" and save it in transaction history + //this needs 2 acct inputs, the from and to, to save it to history + screen.completeResultSP(accts[0], accts[0]); + + //3 + //prints out "Which acct?" + screen.withdrawPromptSP(); + //The users enter which acct is being withdrawn from + screen.enterAccount(); + //there needs to be code in here that actually withdraws the money + //print out "action performed successfully" and save it in transaction history + //this needs 1 acct input to save it to history + screen.completeResultSP(accts[0]); + + //4 + //prints out "Which acct?" + screen.depositPromptSP(); + //The users enter which acct is being deposited to + screen.enterAccount(); + //there needs to be code in here that actually deposits the money + //print out "action performed successfully" and save it in transaction history + //this needs 1 acct input to save it to history + screen.completeResultSP(accts[0]); + + //5 + //"What kind of acct are you opening", takes a string + screen.openPrompt(); + //code in here that does the thing + + //6 + //"Which acct are you closing" + screen.closePrompt(); + //The user enters which acct to close + screen.enterAccount(); + //code in here that does the thing + + //7 + //all 7 does is print transaction history, the fun stuff is in other methods + screen.printHistory(); + + //8 + //all 8 does is log out + //take us back to the initial screen! + + + + } + + + } diff --git a/src/main/java/Workflow.java b/src/main/java/Workflow.java index 3f83385..d2f8d20 100644 --- a/src/main/java/Workflow.java +++ b/src/main/java/Workflow.java @@ -3,13 +3,13 @@ public class Workflow { Display d; Console c; String lastAction; - Integer lastAmount; + Double lastAmount; public Workflow(){ d = new Display(); c = new Console(); lastAction = ""; - lastAmount = 0; + lastAmount = 0.0; } public void errorSP(){ @@ -26,6 +26,10 @@ public Integer getInput(){ + //include input for customername + + //initial opening of an account + deposit. double and string + public void newUserSP(){ d.currentDisplaySP("Input your username, then password twice, or type one lowercase x now to cancel."); } @@ -48,6 +52,14 @@ public String getPassSP(){ return c.getStringInput("Enter password:"); } + public String getNameSP(){ + return ""; + } + + public void initialAccountOpen(){ + //user input double and string + } + public void mainMenuSP(Customer customer){ @@ -85,8 +97,9 @@ public void transferPromptSP(){ lastAction = " transferred to "; } - public Integer amountPromptSP(){ - lastAmount = c.getIntegerInput("How much?"); + public Double amountPromptSP(){ + //try catch + lastAmount = c.getDoubleInput("How much?"); return lastAmount; } @@ -100,13 +113,17 @@ public void completeResultSP(Account account1, Account account2){ d.addToTransactionHistory("$" + lastAmount + lastAction + "account #" + account1.getAccountNumber() + " to account #" + account2.getAccountNumber() + "\n"); } + public void completeResultsNoHistorySP(){ + d.currentDisplaySP("Action performed successfully.\n"); + } + public String openPrompt(){ return c.getStringInputNotCaseSensitive("What kind of account do you want to open?"); } - public void closePromptSP(){ + public void closePrompt(){ d.currentDisplaySP("What account do you want to close?\nNOTE: The account must be empty."); } diff --git a/src/main/test/WorkflowTest.java b/src/main/test/WorkflowTest.java index 90c08c7..b9a4a60 100644 --- a/src/main/test/WorkflowTest.java +++ b/src/main/test/WorkflowTest.java @@ -15,7 +15,7 @@ public void Test1() { String user = w.getUserSP(); w.mainMenuSP(customer); w.withdrawPromptSP(); - Integer int1 = w.amountPromptSP(); + Double dub1 = w.amountPromptSP(); w.completeResultSP(accts[0]); w.printHistory(); } From b987b6e438043c5d3d2c32c3f1029bf77da85bda Mon Sep 17 00:00:00 2001 From: xiong Date: Sat, 13 Mar 2021 22:06:32 -0500 Subject: [PATCH 24/35] fixed Console getInteger and getDouble --- src/main/java/Console.java | 10 +++++++++- src/main/java/Workflow.java | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/Console.java b/src/main/java/Console.java index d74f765..7254d2b 100644 --- a/src/main/java/Console.java +++ b/src/main/java/Console.java @@ -27,7 +27,11 @@ public String getStringInputNotCaseSensitive(String prompt) { public Integer getIntegerInput(String prompt) { Scanner scanner = new Scanner(System.in); println(prompt); - Integer userInput = scanner.nextInt(); + while (!scanner.hasNextInt()) { + System.out.println("Input is not a number."); + scanner.nextLine(); + } + int userInput = scanner.nextInt(); return userInput; } @@ -35,6 +39,10 @@ public Integer getIntegerInput(String prompt) { public Double getDoubleInput(String prompt) { Scanner scanner = new Scanner(System.in); println(prompt); + while (!scanner.hasNextDouble()) { + System.out.println("Input is not a number."); + scanner.nextLine(); + } Double userInput = scanner.nextDouble(); return userInput; diff --git a/src/main/java/Workflow.java b/src/main/java/Workflow.java index d2f8d20..a95831f 100644 --- a/src/main/java/Workflow.java +++ b/src/main/java/Workflow.java @@ -68,8 +68,8 @@ public void mainMenuSP(Customer customer){ - public String enterAccount(){ - return c.getStringInputNotCaseSensitive("Enter an account:"); + public int enterAccount(){ + return c.getIntegerInput("Enter an account:"); } public void checkPromptSP(){ From 9c5a9ed5594351ef73e1d16a0212624012d24153 Mon Sep 17 00:00:00 2001 From: hazel Date: Sun, 14 Mar 2021 11:24:27 -0400 Subject: [PATCH 25/35] Checkpointing --- src/main/java/Workflow.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/Workflow.java b/src/main/java/Workflow.java index d2f8d20..d868c80 100644 --- a/src/main/java/Workflow.java +++ b/src/main/java/Workflow.java @@ -68,9 +68,11 @@ public void mainMenuSP(Customer customer){ - public String enterAccount(){ - return c.getStringInputNotCaseSensitive("Enter an account:"); - } + //enter acct type- screen + + //enter acct- int + + public int enterAccount() { return c.getIntegerInput("Enter an account:")} public void checkPromptSP(){ d.currentDisplaySP("What account do you want to check?"); From 31b36047b3927d79449095ebcb5c9bc6c2477970 Mon Sep 17 00:00:00 2001 From: hazel Date: Sun, 14 Mar 2021 11:31:16 -0400 Subject: [PATCH 26/35] Inserted enterAcctType --- src/main/java/Workflow.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/Workflow.java b/src/main/java/Workflow.java index a95831f..b946a33 100644 --- a/src/main/java/Workflow.java +++ b/src/main/java/Workflow.java @@ -72,6 +72,10 @@ public int enterAccount(){ return c.getIntegerInput("Enter an account:"); } + public String enterAccountType(){ + return c.getStringInputNotCaseSensitive("Enter an account:"); + } + public void checkPromptSP(){ d.currentDisplaySP("What account do you want to check?"); } From 8a08377532d1449fc794f50fb557c40ba73ea91c Mon Sep 17 00:00:00 2001 From: xyuan04 <78838190+xyuan04@users.noreply.github.com> Date: Sun, 14 Mar 2021 14:01:11 -0400 Subject: [PATCH 27/35] created and tested Creator Class will finish Database later --- src/main/java/Creator.java | 22 +++++++ src/main/java/Customer.java | 8 ++- src/main/java/Database.java | 7 +++ src/main/java/Main.java | 87 ++++++++++++++++++++++++---- src/main/test/java/CreatorTest.java | 82 ++++++++++++++++++++++++++ src/main/test/java/CustomerTest.java | 6 +- 6 files changed, 194 insertions(+), 18 deletions(-) create mode 100644 src/main/java/Creator.java create mode 100644 src/main/java/Database.java create mode 100644 src/main/test/java/CreatorTest.java diff --git a/src/main/java/Creator.java b/src/main/java/Creator.java new file mode 100644 index 0000000..737bb35 --- /dev/null +++ b/src/main/java/Creator.java @@ -0,0 +1,22 @@ +public class Creator { + + public static Customer createCustomer(String name, String userName, String password, Account... accounts) { + return new Customer(name, userName, password, accounts); + } + + public static Checking createChecking(double initialDeposit) { + Integer newAccountNumber = (int)(Math.random() * ((999-100) + 1) + 100); + return new Checking(newAccountNumber, initialDeposit); + } + + public static Savings createSavings(double initialDeposit) { + Integer newAccountNumber = (int)(Math.random() * ((9999-1000) + 1) + 1000); + return new Savings(newAccountNumber, initialDeposit); + } + + public static Investment createInvestment(double initialDeposit) { + Integer newAccountNumber = (int)(Math.random() * ((99999-10000) + 1) + 10000); + return new Investment(newAccountNumber, initialDeposit); + } + +} diff --git a/src/main/java/Customer.java b/src/main/java/Customer.java index 9778ea3..d4ab5ec 100644 --- a/src/main/java/Customer.java +++ b/src/main/java/Customer.java @@ -6,14 +6,16 @@ public class Customer { private String customerName; private String userName; private String password; - private ArrayList accounts; + private ArrayList accounts = new ArrayList(); - public Customer(String customerName, String userName, String password, Account[] accounts){ + public Customer(String customerName, String userName, String password, Account... accounts) { this.customerName = customerName; this.userName = userName; this.password = password; - this.accounts = new ArrayList(Arrays.asList(accounts)); + if (accounts != null) { + this.accounts.addAll(Arrays.asList(accounts)); + } } public String getCustomerName(){ return this.customerName;} diff --git a/src/main/java/Database.java b/src/main/java/Database.java new file mode 100644 index 0000000..873aade --- /dev/null +++ b/src/main/java/Database.java @@ -0,0 +1,7 @@ +import java.util.ArrayList; + +public class Database { + private ArrayList currentCustomers = new ArrayList(); + + +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 45025f8..a0612bc 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -4,19 +4,13 @@ public class Main { public static void main(String[] args){ - Workflow w = new Workflow(); - - Account acct = new Savings(12, 34.0); - Account[] accts = new Account[1]; - accts[0] = acct; - Customer customer = new Customer("Hazel", "HD", "45", accts); + Main test = new Main(); + Workflow screen = new Workflow(); + Customer xiong = new Customer("xiong", "dj", "gy", new Account[] {new Checking(100, 15000), new Savings(200, 25000), new Investment(300, 50000)}); - String user = w.getUserSP(); - w.mainMenuSP(customer); - w.withdrawPromptSP(); - Double dub1 = w.amountPromptSP(); - w.completeResultSP(accts[0]); - w.printHistory(); + test.deposit(screen, xiong); + test.withdrawal(screen, xiong); + test.transfer(screen, xiong); } public void runEngine(){ @@ -121,6 +115,75 @@ public void runEngine(){ } + public void withdrawal(Workflow screen, Customer customer) { + boolean validAmount = true; + screen.withdrawPromptSP(); + + Integer withdrawAccount = screen.enterAccount(); + while(customer.getAccount(withdrawAccount) == null) { + System.out.println("Account not on file"); + withdrawAccount = screen.enterAccount(); + } + + while (validAmount) { + double withdrawalAmount = screen.amountPromptSP(); + if (customer.getAccount(withdrawAccount).getBalance() > withdrawalAmount) { + customer.getAccount(withdrawAccount).withdraw(withdrawalAmount); + validAmount = false; + } else System.out.println("Non sufficient funds"); + } + + System.out.println(customer.getAccount(withdrawAccount).getBalance()); + screen.completeResultSP(customer.getAccount(withdrawAccount)); + } + + public void deposit(Workflow screen, Customer customer) { + screen.depositPromptSP(); + + Integer depositAccount = screen.enterAccount(); + while(customer.getAccount(depositAccount) == null) { + System.out.println("Account not on file"); + depositAccount = screen.enterAccount(); + } + + double depositAmount = screen.amountPromptSP(); + + customer.getAccount(depositAccount).deposit(depositAmount); + + System.out.println(customer.getAccount(depositAccount).getBalance()); + screen.completeResultSP(customer.getAccount(depositAccount)); + } + + public void transfer(Workflow screen, Customer customer) { + boolean validAmount = true; + screen.transferPromptSP(); + + Integer withdrawAccount = screen.enterAccount(); + while(customer.getAccount(withdrawAccount) == null) { + System.out.println("Account not on file"); + withdrawAccount = screen.enterAccount(); + } + + Integer depositAccount = screen.enterAccount(); + while(customer.getAccount(depositAccount) == null) { + System.out.println("Account not on file"); + depositAccount = screen.enterAccount(); + } + + while (validAmount) { + double transferAmount = screen.amountPromptSP(); + if (customer.getAccount(withdrawAccount).getBalance() >= transferAmount) { + customer.getAccount(withdrawAccount).withdraw(transferAmount); + customer.getAccount(depositAccount).deposit(transferAmount); + validAmount = false; + } else System.out.println("Non sufficient funds"); + } + + System.out.println(customer.getAccount(withdrawAccount).getBalance()); + System.out.println(customer.getAccount(depositAccount).getBalance()); + screen.completeResultSP(customer.getAccount(withdrawAccount), customer.getAccount(depositAccount)); + } + } diff --git a/src/main/test/java/CreatorTest.java b/src/main/test/java/CreatorTest.java new file mode 100644 index 0000000..3745b7b --- /dev/null +++ b/src/main/test/java/CreatorTest.java @@ -0,0 +1,82 @@ +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CreatorTest { + + @Test + public void createChecking() { + // : Given + double initialDeposit = 5000; + + // : When + Checking checking101 = Creator.createChecking(initialDeposit); + double actualBalance = checking101.getBalance(); + + System.out.println(checking101.getAccountNumber()); + System.out.println(checking101.getBalance()); + + // : Then + Assert.assertEquals(initialDeposit, actualBalance, 0.00001); + Assert.assertTrue(checking101.getAccountNumber() <= 999 & checking101.getAccountNumber() >= 100); + } + + @Test + public void createSavings() { + // : Given + double initialDeposit = 25000; + + // : When + Savings savings101 = Creator.createSavings(initialDeposit); + double actualBalance = savings101.getBalance(); + + System.out.println(savings101.getAccountNumber()); + System.out.println(savings101.getBalance()); + + // : Then + Assert.assertEquals(initialDeposit, actualBalance, 0.00001); + Assert.assertTrue(savings101.getAccountNumber() <= 9999 & savings101.getAccountNumber() >= 1000); + } + + @Test + public void createInvestment() { + // : Given + double initialDeposit = 50000; + + // : When + Investment investment101 = Creator.createInvestment(initialDeposit); + double actualBalance = investment101.getBalance(); + + System.out.println(investment101.getAccountNumber()); + System.out.println(investment101.getBalance()); + + // : Then + Assert.assertEquals(initialDeposit, actualBalance, 0.00001); + Assert.assertTrue(investment101.getAccountNumber() <= 99999 & investment101.getAccountNumber() >= 10000); + } + + @Test + public void createCustomer() { + // : Given + String name = "Bruce Wayne"; + String userName = "Batman"; + String password = "Gotham"; + Checking checking101 = Creator.createChecking(500); + Savings savings101 = Creator.createSavings(2500); + Investment investment101 = Creator.createInvestment(5000); + + // : When + Customer bruce = Creator.createCustomer(name, userName, password, checking101, savings101, investment101); + String actualName = bruce.getCustomerName(); + String actualUserName = bruce.getUserName(); + String actualPassword = bruce.getPassword(); + + System.out.println(bruce.getAccountNumber()); + + // : Then + Assert.assertEquals(name, actualName); + Assert.assertEquals(userName, actualUserName); + Assert.assertEquals(password, actualPassword); + } +} \ No newline at end of file diff --git a/src/main/test/java/CustomerTest.java b/src/main/test/java/CustomerTest.java index 39f2beb..7d5770d 100644 --- a/src/main/test/java/CustomerTest.java +++ b/src/main/test/java/CustomerTest.java @@ -10,14 +10,14 @@ public void customerConstuctor() { String userName = "xyuan"; String password = "zipcode0"; Account checkingAccount = new Checking(24231, 23142); - Account[] accounts = new Account[]{checkingAccount}; + Account savingsAccount = new Savings(111, 25000); // : When - Customer xiong = new Customer(customerName, userName, password, accounts); + Customer xiong = new Customer(customerName, userName, password, checkingAccount, savingsAccount); String actualName = xiong.getCustomerName(); String actualUserName = xiong.getUserName(); String actualPassword = xiong.getPassword(); - String account = "24231\n"; + String account = "24231\n" + "111\n"; String actualAccount = xiong.getAccountNumber(); // : Then From afaaeb694b05949c81c65263d42589df540a24df Mon Sep 17 00:00:00 2001 From: xyuan04 <78838190+xyuan04@users.noreply.github.com> Date: Sun, 14 Mar 2021 15:06:03 -0400 Subject: [PATCH 28/35] created and tested Database --- src/main/java/Database.java | 27 +++++++- src/main/test/java/DatabaseTest.java | 93 ++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/main/test/java/DatabaseTest.java diff --git a/src/main/java/Database.java b/src/main/java/Database.java index 873aade..2eddf2b 100644 --- a/src/main/java/Database.java +++ b/src/main/java/Database.java @@ -1,7 +1,32 @@ import java.util.ArrayList; public class Database { - private ArrayList currentCustomers = new ArrayList(); + private static volatile ArrayList currentCustomers = new ArrayList(); + + public static void addCustomer(Customer customer) { + currentCustomers.add(customer); + } + + public static Customer getCustomerByName(String name) { + for(Customer customer : currentCustomers) { + if(customer.getCustomerName().equals(name)) { + return customer; + } + } + return null; + } + + public static void removeCustomer(Customer customer) { + currentCustomers.remove(customer); + } + + public static Integer getNumberOfCustomers() { + return currentCustomers.size(); + } + + public static void removeAllCustomers() { + currentCustomers.clear(); + } } diff --git a/src/main/test/java/DatabaseTest.java b/src/main/test/java/DatabaseTest.java new file mode 100644 index 0000000..ffbefda --- /dev/null +++ b/src/main/test/java/DatabaseTest.java @@ -0,0 +1,93 @@ +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class DatabaseTest { + + @Test + public void addCustomer() { + // : Given + Checking bruceChecking = Creator.createChecking(100); + Savings bruceSaving = Creator.createSavings(500); + Customer bruce = Creator.createCustomer("Bruce", "Bat", "Gotham", bruceChecking, bruceSaving); + + // : When + Database.removeAllCustomers(); + Database.addCustomer(bruce); + int expected = 1; + int actual = Database.getNumberOfCustomers(); + + System.out.println(Database.getNumberOfCustomers()); + + // : Then + Assert.assertEquals(expected, actual); + } + + @Test + public void getCustomerByName() { + Checking bruceChecking = Creator.createChecking(100); + Savings bruceSaving = Creator.createSavings(500); + Checking batmanChecking = Creator.createChecking(500); + Savings batmanSavings = Creator.createSavings(1000); + Customer bruce = Creator.createCustomer("Bruce", "Bat", "Gotham", bruceChecking, bruceSaving); + Customer batman = Creator.createCustomer("Batman", "h", "y", batmanChecking, batmanSavings); + + // : When + Database.removeAllCustomers(); + Database.addCustomer(bruce); + Database.addCustomer(batman); + Customer expected = batman; + Customer actual = Database.getCustomerByName("Batman"); + + System.out.println(Database.getNumberOfCustomers()); + + // : Then + Assert.assertEquals(expected, actual); + } + + @Test + public void removeCustomer() { + Checking bruceChecking = Creator.createChecking(100); + Savings bruceSaving = Creator.createSavings(500); + Checking batmanChecking = Creator.createChecking(500); + Savings batmanSavings = Creator.createSavings(1000); + Customer bruce = Creator.createCustomer("Bruce", "Bat", "Gotham", bruceChecking, bruceSaving); + Customer batman = Creator.createCustomer("Batman", "h", "y", batmanChecking, batmanSavings); + + // : When + Database.removeAllCustomers(); + Database.addCustomer(bruce); + Database.addCustomer(batman); + Database.removeCustomer(bruce); + int expected = 1; + int actual = Database.getNumberOfCustomers(); + + System.out.println(Database.getNumberOfCustomers()); + + // : Then + Assert.assertEquals(expected, actual); + } + + @Test + public void removeAllCustomers() { + Checking bruceChecking = Creator.createChecking(100); + Savings bruceSaving = Creator.createSavings(500); + Checking batmanChecking = Creator.createChecking(500); + Savings batmanSavings = Creator.createSavings(1000); + Customer bruce = Creator.createCustomer("Bruce", "Bat", "Gotham", bruceChecking, bruceSaving); + Customer batman = Creator.createCustomer("Batman", "h", "y", batmanChecking, batmanSavings); + + // : When + Database.addCustomer(bruce); + Database.addCustomer(batman); + Database.removeAllCustomers(); + int expected = 0; + int actual = Database.getNumberOfCustomers(); + + System.out.println(Database.getNumberOfCustomers()); + + // : Then + Assert.assertEquals(expected, actual); + } +} \ No newline at end of file From 600288bc8c138ef1664cdfc7d3ef8218d9a0acdf Mon Sep 17 00:00:00 2001 From: xyuan04 <78838190+xyuan04@users.noreply.github.com> Date: Sun, 14 Mar 2021 16:49:10 -0400 Subject: [PATCH 29/35] * added methods in Customer and Database + tested --- src/main/java/Customer.java | 15 ++---- src/main/java/Database.java | 9 ++++ src/main/test/java/CustomerTest.java | 76 ++++++---------------------- src/main/test/java/DatabaseTest.java | 30 +++++++++-- 4 files changed, 55 insertions(+), 75 deletions(-) diff --git a/src/main/java/Customer.java b/src/main/java/Customer.java index d4ab5ec..e31b69b 100644 --- a/src/main/java/Customer.java +++ b/src/main/java/Customer.java @@ -55,19 +55,12 @@ public Account getAccount(int accountNumber) { return null; } - public void openCheckingAccount(int accountNumber, double initialDeposit) { - Checking newAccount = new Checking(accountNumber, initialDeposit); - accounts.add(newAccount); + public void addAccount(Account account) { + accounts.add(account); } - public void openSavingsAccount(int accountNumber, double initialDeposit) { - Savings newAccount = new Savings(accountNumber, initialDeposit); - accounts.add(newAccount); - } - - public void openInvestmentAccount(int accountNumber, double initialDeposit) { - Investment newAccount = new Investment(accountNumber, initialDeposit); - accounts.add(newAccount); + public int getNumberOfAccounts() { + return accounts.size(); } public void closeAccount(Integer accountNumber) { diff --git a/src/main/java/Database.java b/src/main/java/Database.java index 2eddf2b..de5fb4d 100644 --- a/src/main/java/Database.java +++ b/src/main/java/Database.java @@ -16,6 +16,15 @@ public static Customer getCustomerByName(String name) { return null; } + public static Customer getCustomerByUsername(String username) { + for(Customer customer : currentCustomers) { + if(customer.getUserName().equals(username)) { + return customer; + } + } + return null; + } + public static void removeCustomer(Customer customer) { currentCustomers.remove(customer); } diff --git a/src/main/test/java/CustomerTest.java b/src/main/test/java/CustomerTest.java index 7d5770d..f27f1aa 100644 --- a/src/main/test/java/CustomerTest.java +++ b/src/main/test/java/CustomerTest.java @@ -143,68 +143,24 @@ public void getAccountNumber() { Assert.assertEquals(account, actualAccount); } - @Test - public void testOpenCheckingAccount() { - // : Given - String customerName = "Bruce Wayne"; - String userName = "NotBatman"; - String password = "zipcode0"; - Account checkingAccount = new Checking(32563, 915252956); - Account savingsAccount = new Savings(992223, 750); - Account investAccount = new Investment(111, 50000); - Account[] accounts = new Account[]{checkingAccount, savingsAccount, investAccount}; - // : When - String account = "32563\n" + "992223\n" + "111\n" + "69420\n"; - Customer wayne = new Customer(customerName, userName, password, accounts); - wayne.openCheckingAccount(69420, 50000); - String actualAccount = wayne.getAccountNumber(); - - System.out.println(actualAccount); - // : Then - Assert.assertEquals(account, actualAccount); - } - - @Test - public void testOpenSavingsAccount() { - // : Given - String customerName = "Bruce Wayne"; - String userName = "NotBatman"; - String password = "zipcode0"; - Account checkingAccount = new Checking(32563, 915252956); - Account savingsAccount = new Savings(992223, 750); - Account investAccount = new Investment(111, 50000); - Account[] accounts = new Account[]{checkingAccount, savingsAccount, investAccount}; - // : When - String account = "32563\n" + "992223\n" + "111\n" + "6969\n"; - Customer wayne = new Customer(customerName, userName, password, accounts); - wayne.openSavingsAccount(6969, 50000); - String actualAccount = wayne.getAccountNumber(); - - System.out.println(actualAccount); - // : Then - Assert.assertEquals(account, actualAccount); - } + @Test + public void addAccountTest() { + // : Given + String customerName = "Bruce Wayne"; + String userName = "NotBatman"; + String password = "zipcode0"; + Account checkingAccount = new Checking(32563, 915252956); + Customer wayne = new Customer(customerName, userName, password, checkingAccount); - @Test - public void testOpenInvestmentAccount() { - // : Given - String customerName = "Bruce Wayne"; - String userName = "NotBatman"; - String password = "zipcode0"; - Account checkingAccount = new Checking(32563, 915252956); - Account savingsAccount = new Savings(992223, 750); - Account investAccount = new Investment(111, 50000); - Account[] accounts = new Account[]{checkingAccount, savingsAccount, investAccount}; - // : When - String account = "32563\n" + "992223\n" + "111\n" + "420420\n"; - Customer wayne = new Customer(customerName, userName, password, accounts); - wayne.openInvestmentAccount(420420, 50000); - String actualAccount = wayne.getAccountNumber(); + // : When + Account savingsAccount = Creator.createSavings(5000); + wayne.addAccount(savingsAccount); + int expected = 2; + int actual = wayne.getNumberOfAccounts(); - System.out.println(actualAccount); - // : Then - Assert.assertEquals(account, actualAccount); - } + // : Then + Assert.assertEquals(expected, actual); + } @Test public void testCloseAccountWithBalance() { diff --git a/src/main/test/java/DatabaseTest.java b/src/main/test/java/DatabaseTest.java index ffbefda..144fe45 100644 --- a/src/main/test/java/DatabaseTest.java +++ b/src/main/test/java/DatabaseTest.java @@ -6,7 +6,7 @@ public class DatabaseTest { @Test - public void addCustomer() { + public void addCustomerTest() { // : Given Checking bruceChecking = Creator.createChecking(100); Savings bruceSaving = Creator.createSavings(500); @@ -25,7 +25,7 @@ public void addCustomer() { } @Test - public void getCustomerByName() { + public void getCustomerByNameTest() { Checking bruceChecking = Creator.createChecking(100); Savings bruceSaving = Creator.createSavings(500); Checking batmanChecking = Creator.createChecking(500); @@ -47,7 +47,29 @@ public void getCustomerByName() { } @Test - public void removeCustomer() { + public void getCustomerByUsernameTest() { + Checking bruceChecking = Creator.createChecking(100); + Savings bruceSaving = Creator.createSavings(500); + Checking batmanChecking = Creator.createChecking(500); + Savings batmanSavings = Creator.createSavings(1000); + Customer bruce = Creator.createCustomer("Bruce", "Bat", "Gotham", bruceChecking, bruceSaving); + Customer batman = Creator.createCustomer("Batman", "h", "y", batmanChecking, batmanSavings); + + // : When + Database.removeAllCustomers(); + Database.addCustomer(bruce); + Database.addCustomer(batman); + Customer expected = batman; + Customer actual = Database.getCustomerByUsername("h"); + + System.out.println(Database.getNumberOfCustomers()); + + // : Then + Assert.assertEquals(expected, actual); + } + + @Test + public void removeCustomerTest() { Checking bruceChecking = Creator.createChecking(100); Savings bruceSaving = Creator.createSavings(500); Checking batmanChecking = Creator.createChecking(500); @@ -70,7 +92,7 @@ public void removeCustomer() { } @Test - public void removeAllCustomers() { + public void removeAllCustomersTest() { Checking bruceChecking = Creator.createChecking(100); Savings bruceSaving = Creator.createSavings(500); Checking batmanChecking = Creator.createChecking(500); From c3f1160189bfffd1144ed5119a9f9b337405c9b5 Mon Sep 17 00:00:00 2001 From: Lena Date: Sun, 14 Mar 2021 17:25:26 -0400 Subject: [PATCH 30/35] opening and closing account --- src/main/java/Main.java | 197 ++++++++++++++++++++++++++-------------- 1 file changed, 130 insertions(+), 67 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a0612bc..91f907e 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -6,11 +6,15 @@ public class Main { public static void main(String[] args){ Main test = new Main(); Workflow screen = new Workflow(); - Customer xiong = new Customer("xiong", "dj", "gy", new Account[] {new Checking(100, 15000), new Savings(200, 25000), new Investment(300, 50000)}); - - test.deposit(screen, xiong); - test.withdrawal(screen, xiong); - test.transfer(screen, xiong); + Customer lena = new Customer("Lena", "Bach", "123", new Account[] {new Checking(111,0.0),new Investment(222,800)} ); + // test.closingAccount(screen,lena); + test.openingAccount(screen,lena); +// Workflow screen = new Workflow();saving +// Customer xiong = new Customer("xiong", "dj", "gy", new Account[] {new Checking(100, 15000), new Savings(200, 25000), new Investment(300, 50000)}); +// +// test.deposit(screen, xiong); +// test.withdrawal(screen, xiong); +// test.transfer(screen, xiong); } public void runEngine(){ @@ -115,75 +119,134 @@ public void runEngine(){ } - public void withdrawal(Workflow screen, Customer customer) { - boolean validAmount = true; - screen.withdrawPromptSP(); - - Integer withdrawAccount = screen.enterAccount(); - while(customer.getAccount(withdrawAccount) == null) { - System.out.println("Account not on file"); - withdrawAccount = screen.enterAccount(); - } - - while (validAmount) { - double withdrawalAmount = screen.amountPromptSP(); - if (customer.getAccount(withdrawAccount).getBalance() > withdrawalAmount) { - customer.getAccount(withdrawAccount).withdraw(withdrawalAmount); - validAmount = false; - } else System.out.println("Non sufficient funds"); - } - - System.out.println(customer.getAccount(withdrawAccount).getBalance()); - screen.completeResultSP(customer.getAccount(withdrawAccount)); +// public void withdrawal(Workflow screen, Customer customer) { +// boolean validAmount = true; +// screen.withdrawPromptSP(); +// +// Integer withdrawAccount = screen.enterAccount(); +// while(customer.getAccount(withdrawAccount) == null) { +// System.out.println("Account not on file"); +// withdrawAccount = screen.enterAccount(); +// } +// +// while (validAmount) { +// double withdrawalAmount = screen.amountPromptSP(); +// if (customer.getAccount(withdrawAccount).getBalance() > withdrawalAmount) { +// customer.getAccount(withdrawAccount).withdraw(withdrawalAmount); +// validAmount = false; +// } else System.out.println("Non sufficient funds"); +// } +// +// System.out.println(customer.getAccount(withdrawAccount).getBalance()); +// screen.completeResultSP(customer.getAccount(withdrawAccount)); +// } +// +// public void deposit(Workflow screen, Customer customer) { +// screen.depositPromptSP(); +// +// Integer depositAccount = screen.enterAccount(); +// while(customer.getAccount(depositAccount) == null) { +// System.out.println("Account not on file"); +// depositAccount = screen.enterAccount(); +// } +// +// double depositAmount = screen.amountPromptSP(); +// +// customer.getAccount(depositAccount).deposit(depositAmount); +// +// System.out.println(customer.getAccount(depositAccount).getBalance()); +// screen.completeResultSP(customer.getAccount(depositAccount)); +// } +// +// public void transfer(Workflow screen, Customer customer) { +// boolean validAmount = true; +// screen.transferPromptSP(); +// +// Integer withdrawAccount = screen.enterAccount(); +// while(customer.getAccount(withdrawAccount) == null) { +// System.out.println("Account not on file"); +// withdrawAccount = screen.enterAccount(); +// } +// +// Integer depositAccount = screen.enterAccount(); +// while(customer.getAccount(depositAccount) == null) { +// System.out.println("Account not on file"); +// depositAccount = screen.enterAccount(); +// } +// +// while (validAmount) { +// double transferAmount = screen.amountPromptSP(); +// if (customer.getAccount(withdrawAccount).getBalance() >= transferAmount) { +// customer.getAccount(withdrawAccount).withdraw(transferAmount); +// customer.getAccount(depositAccount).deposit(transferAmount); +// validAmount = false; +// } else System.out.println("Non sufficient funds"); +// } +// +// System.out.println(customer.getAccount(withdrawAccount).getBalance()); +// System.out.println(customer.getAccount(depositAccount).getBalance()); +// screen.completeResultSP(customer.getAccount(withdrawAccount), customer.getAccount(depositAccount)); +// } +public void closingAccount(Workflow screen, Customer customer) { + screen.closePrompt(); + Integer oldAccount=screen.enterAccount(); + Boolean validAccount=true; + while(customer.getAccount(oldAccount)==null){ + System.out.println("Account not on file"); + oldAccount=screen.enterAccount(); } - - public void deposit(Workflow screen, Customer customer) { - screen.depositPromptSP(); - - Integer depositAccount = screen.enterAccount(); - while(customer.getAccount(depositAccount) == null) { - System.out.println("Account not on file"); - depositAccount = screen.enterAccount(); + while(validAccount){ + if(customer.getAccount(oldAccount).getBalance()==0) + { + customer.closeAccount(oldAccount); + break; + } + else { + System.out.println("Must be empty"); + System.out.println("Remaining balance: $"+customer.getAccount(oldAccount).getBalance()); + break; } - double depositAmount = screen.amountPromptSP(); - - customer.getAccount(depositAccount).deposit(depositAmount); - - System.out.println(customer.getAccount(depositAccount).getBalance()); - screen.completeResultSP(customer.getAccount(depositAccount)); } + System.out.println("User accounts: "+"\n"+customer.getAccountNumber()); + screen.completeResultsNoHistorySP(); +} - public void transfer(Workflow screen, Customer customer) { - boolean validAmount = true; - screen.transferPromptSP(); - - Integer withdrawAccount = screen.enterAccount(); - while(customer.getAccount(withdrawAccount) == null) { - System.out.println("Account not on file"); - withdrawAccount = screen.enterAccount(); - } - - Integer depositAccount = screen.enterAccount(); - while(customer.getAccount(depositAccount) == null) { - System.out.println("Account not on file"); - depositAccount = screen.enterAccount(); - } + public void openingAccount(Workflow screen,Customer customer) { + String uniqAccount = screen.openPrompt(); + boolean validType = true; + while (validType) { + if ("checking".equals(uniqAccount)) { + double firstCheckingDeposit = screen.amountPromptSP(); + Checking uniqChecking = Creator.createChecking(firstCheckingDeposit); + customer.addAccount(uniqChecking); + System.out.println(uniqChecking.getAccountNumber()); + System.out.println(uniqChecking.getBalance()); + System.out.println("User accounts: "+"\n"+customer.getAccountNumber()); + break; + } else if ("savings".equals(uniqAccount)) { + double firstSavingDeposit = screen.amountPromptSP(); + Checking uniqSaving = Creator.createChecking(firstSavingDeposit); + customer.addAccount(uniqSaving); + System.out.println(uniqSaving.getAccountNumber()); + System.out.println(uniqSaving.getBalance()); + System.out.println("User accounts: "+"\n"+customer.getAccountNumber()); + break; + } else if ("investment".equals(uniqAccount)) { + double firstInvestmentDeposit = screen.amountPromptSP(); + Checking uniqInvestment = Creator.createChecking(firstInvestmentDeposit); + customer.addAccount(uniqInvestment); + System.out.println(uniqInvestment.getAccountNumber()); + System.out.println(uniqInvestment.getBalance()); + System.out.println("User accounts: "+"\n"+customer.getAccountNumber()); + break; + } else + { + System.out.println("Not a valid entry. Please type in checking, savings, investment"); + uniqAccount = screen.openPrompt(); + } - while (validAmount) { - double transferAmount = screen.amountPromptSP(); - if (customer.getAccount(withdrawAccount).getBalance() >= transferAmount) { - customer.getAccount(withdrawAccount).withdraw(transferAmount); - customer.getAccount(depositAccount).deposit(transferAmount); - validAmount = false; - } else System.out.println("Non sufficient funds"); } - System.out.println(customer.getAccount(withdrawAccount).getBalance()); - System.out.println(customer.getAccount(depositAccount).getBalance()); - screen.completeResultSP(customer.getAccount(withdrawAccount), customer.getAccount(depositAccount)); } - - - } From cccae942add91fa8236913898792b77934211640 Mon Sep 17 00:00:00 2001 From: MNinh <78838228+MNinh@users.noreply.github.com> Date: Sun, 14 Mar 2021 18:51:37 -0400 Subject: [PATCH 31/35] added login menu and create customer --- src/main/java/Main.java | 145 ++++++++++++++++++++++++++++++++++-- src/main/java/Workflow.java | 11 ++- 2 files changed, 150 insertions(+), 6 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 91f907e..864d66b 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -3,20 +3,155 @@ */ public class Main { - public static void main(String[] args){ + public static void main(String[] args) { Main test = new Main(); - Workflow screen = new Workflow(); - Customer lena = new Customer("Lena", "Bach", "123", new Account[] {new Checking(111,0.0),new Investment(222,800)} ); - // test.closingAccount(screen,lena); - test.openingAccount(screen,lena); +// Workflow screen = new Workflow(); +// Customer lena = new Customer("Lena", "Bach", "123", new Account[] {new Checking(111,0.0),new Investment(222,800)} ); +// // test.closingAccount(screen,lena); +// test.openingAccount(screen,lena); // Workflow screen = new Workflow();saving // Customer xiong = new Customer("xiong", "dj", "gy", new Account[] {new Checking(100, 15000), new Savings(200, 25000), new Investment(300, 50000)}); // // test.deposit(screen, xiong); // test.withdrawal(screen, xiong); // test.transfer(screen, xiong); + test.customerLogin(); } + public void customerLogin() { + Workflow screen = new Workflow(); + screen.initialWelcomeSP(); + boolean test = true; + //Starting screen + Integer input = screen.getInput(); + //1 for new user, 2 for returning. this /just/ takes the number tho + while (test) + switch (input) { + case 1: + createCustomer(); + test = false; + break; + case 2: + returningCustomer(); + test = false; + break; + case 0: + System.out.println("Thank you for using this ATM, have a nice day!"); + test = false; + break; + default: + input = screen.getInput(); + System.out.println("Please choose use 1 for new customer or 2 for returning customer, 0 to exit."); + break; + } + } + + //path 1 + //prompts new user for the necessary info + //name + public void createCustomer() { + Workflow screen = new Workflow(); + Customer newCustomer = Creator.createCustomer(null, null, null, null); + String newCustomerName = screen.getCustomerNameSP(); + screen.newUserSP(); + String newUsername = screen.getUserSP(); + boolean user = true; + while (user) + if (Database.getCustomerByUsername(newUsername) != null) { + screen.usernameTakenSP(); + newUsername = screen.getUserSP(); + } else { + newCustomer.setUserName(newUsername); + user = false; + } + + boolean pass = true; + + while (pass) { + String newPassword = screen.getPassSP(); + String newPasswordConfirm = screen.getPassSP(); + if (newPasswordConfirm.equals(newPassword)) { + + newCustomer.setPassword(newPassword); + pass = false; + } else { + screen.passwordMismatchSP(); + + } + } + + System.out.println("Please type Checking, Savings, Investments"); + openingAccount(screen, newCustomer); + + + +// System.out.println("What type of account do you want to open?\n 1 for Checking\n 2 for Savings\n 3 for Investment\n 0 to go back to login"); +// Integer testing = screen.getInput(); +// +// boolean openAcc = true; +// while (openAcc) +// switch (testing) { +// case 1: +// +// case 2: +// +// case 3: +// +// case 0: +// System.out.println("Thank you for using this ATM!"); +// openAcc = false; +// customerLogin(); +// break; +// default: +// testing = screen.getInput(); +// System.out.println("Please choose use 1 for checking, 2 for savings, 3 for investment, or 0 to exit to login screen."); +// break; +// } + } + + +// //enter password twice. check to see if they match + +// if (newPassword != newPasswordConfirm) { +// screen.passwordMismatchSP(); +// +// } else if (newPassword == newPasswordConfirm) { +// screen.initialAccountOpen(); +// } + //initial deposit + + + // path 2 +// prompts returning user for the necessary info +// username +// + + public void returningCustomer(){ + + Workflow screen = new Workflow(); + Customer mike = new Customer("Mike Ninh", + "msn", + "123", + new Account[]{new Savings(231412, 233)}); + + screen.returningUserSP(); + String userName; + String password; + if(mike.getUserName() != screen.getUserSP()){ + System.out.println("Username not found please try again"); + returningCustomer(); + }else{ + + } + } + +// screen.getUserSP(); +// //password, in while loop, which will kick user out if they fail three times +// screen.getPassSP(); + + + + public void runEngine(){ Workflow screen = new Workflow(); diff --git a/src/main/java/Workflow.java b/src/main/java/Workflow.java index b946a33..3110984 100644 --- a/src/main/java/Workflow.java +++ b/src/main/java/Workflow.java @@ -17,7 +17,7 @@ public void errorSP(){ } public void initialWelcomeSP(){ - d.currentDisplaySP("Welcome to the ATM! Are you a new or returning user?\nEnter 1 for new, 2 for returning."); + d.currentDisplaySP("Welcome to the ATM! Are you a new or returning user?\nEnter 1 for new, 2 for returning, 0 to exit atm."); } public Integer getInput(){ @@ -27,7 +27,16 @@ public Integer getInput(){ //include input for customername + public void newCustomerNameSP(){ + d.currentDisplaySP("Enter your Name"); + } + public String getCustomerNameSP(){ + return c.getStringInput(("Your name here")); + } + public void usernameTakenSP(){ + d.currentDisplaySP("Username is already taken. Please try again."); + } //initial opening of an account + deposit. double and string public void newUserSP(){ From 17a6e4d60e271c61fc232ec1b70babd1dc72cc06 Mon Sep 17 00:00:00 2001 From: xyuan04 <78838190+xyuan04@users.noreply.github.com> Date: Sun, 14 Mar 2021 19:10:55 -0400 Subject: [PATCH 32/35] updated main, account, database --- src/main/java/Account.java | 4 +++- src/main/java/Database.java | 5 +++++ src/main/java/Main.java | 19 ++++++++----------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/Account.java b/src/main/java/Account.java index e7349e5..2bb2c48 100644 --- a/src/main/java/Account.java +++ b/src/main/java/Account.java @@ -23,7 +23,9 @@ public double withdraw(double amount) { } public double deposit(double amount) { - return balance += amount; + if (amount > 0) { + return balance += amount; + } else return balance; } } diff --git a/src/main/java/Database.java b/src/main/java/Database.java index de5fb4d..63cadb7 100644 --- a/src/main/java/Database.java +++ b/src/main/java/Database.java @@ -1,4 +1,5 @@ import java.util.ArrayList; +import java.util.Arrays; public class Database { private static volatile ArrayList currentCustomers = new ArrayList(); @@ -7,6 +8,10 @@ public static void addCustomer(Customer customer) { currentCustomers.add(customer); } + public static void addMultipleCustomers(Customer... customer) { + currentCustomers.addAll(Arrays.asList(customer)); + } + public static Customer getCustomerByName(String name) { for(Customer customer : currentCustomers) { if(customer.getCustomerName().equals(name)) { diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 864d66b..1662086 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -2,20 +2,17 @@ * Created by iyasuwatts on 10/17/17. */ public class Main { + private boolean engineOn = true; public static void main(String[] args) { Main test = new Main(); -// Workflow screen = new Workflow(); -// Customer lena = new Customer("Lena", "Bach", "123", new Account[] {new Checking(111,0.0),new Investment(222,800)} ); -// // test.closingAccount(screen,lena); -// test.openingAccount(screen,lena); -// Workflow screen = new Workflow();saving -// Customer xiong = new Customer("xiong", "dj", "gy", new Account[] {new Checking(100, 15000), new Savings(200, 25000), new Investment(300, 50000)}); -// -// test.deposit(screen, xiong); -// test.withdrawal(screen, xiong); -// test.transfer(screen, xiong); - test.customerLogin(); + Workflow screen = new Workflow(); + Customer xiong = Creator.createCustomer("xiong", "xyuan", "zipcode", new Checking(100, 1500), new Savings(100, 2500), new Investment(10000, 6000)); + Customer mike = Creator.createCustomer("mike", "ninh", "zipcode", new Checking(101, 1500), new Savings(1001, 2500), new Investment(10001, 6000)); + Customer hazel = Creator.createCustomer("hazel", "hbecker", "zipcode", new Checking(102, 1500), new Savings(1002, 2500), new Investment(10002, 6000)); + Customer lena = Creator.createCustomer("lena", "llitouka", "zipcode", new Checking(103, 1500), new Savings(1003, 2500), new Investment(10003, 6000)); + Database.addMultipleCustomers(xiong, mike, hazel, lena); + } public void customerLogin() { From 16c4cba7528c12fd0fedf819f1b03b3662f06986 Mon Sep 17 00:00:00 2001 From: xyuan04 <78838190+xyuan04@users.noreply.github.com> Date: Sun, 14 Mar 2021 22:42:59 -0400 Subject: [PATCH 33/35] finalized ATM --- src/main/java/Main.java | 371 +-------------------------------- src/main/java/Motherboard.java | 258 +++++++++++++++++++++++ src/main/java/Workflow.java | 10 +- 3 files changed, 266 insertions(+), 373 deletions(-) create mode 100644 src/main/java/Motherboard.java diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 1662086..e58a335 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -5,380 +5,15 @@ public class Main { private boolean engineOn = true; public static void main(String[] args) { - Main test = new Main(); Workflow screen = new Workflow(); - Customer xiong = Creator.createCustomer("xiong", "xyuan", "zipcode", new Checking(100, 1500), new Savings(100, 2500), new Investment(10000, 6000)); + Customer xiong = Creator.createCustomer("xiong", "xyuan", "zipcode", new Checking(100, 1500), new Savings(1000, 2500), new Investment(10000, 6000)); Customer mike = Creator.createCustomer("mike", "ninh", "zipcode", new Checking(101, 1500), new Savings(1001, 2500), new Investment(10001, 6000)); Customer hazel = Creator.createCustomer("hazel", "hbecker", "zipcode", new Checking(102, 1500), new Savings(1002, 2500), new Investment(10002, 6000)); Customer lena = Creator.createCustomer("lena", "llitouka", "zipcode", new Checking(103, 1500), new Savings(1003, 2500), new Investment(10003, 6000)); Database.addMultipleCustomers(xiong, mike, hazel, lena); - } - - public void customerLogin() { - Workflow screen = new Workflow(); - screen.initialWelcomeSP(); - boolean test = true; - //Starting screen - Integer input = screen.getInput(); - //1 for new user, 2 for returning. this /just/ takes the number tho - while (test) - switch (input) { - case 1: - createCustomer(); - test = false; - break; - case 2: - returningCustomer(); - test = false; - break; - case 0: - System.out.println("Thank you for using this ATM, have a nice day!"); - test = false; - break; - default: - input = screen.getInput(); - System.out.println("Please choose use 1 for new customer or 2 for returning customer, 0 to exit."); - break; - } - } - - //path 1 - //prompts new user for the necessary info - //name - public void createCustomer() { - Workflow screen = new Workflow(); - Customer newCustomer = Creator.createCustomer(null, null, null, null); - String newCustomerName = screen.getCustomerNameSP(); - screen.newUserSP(); - String newUsername = screen.getUserSP(); - boolean user = true; - while (user) - if (Database.getCustomerByUsername(newUsername) != null) { - screen.usernameTakenSP(); - newUsername = screen.getUserSP(); - } else { - newCustomer.setUserName(newUsername); - user = false; - } - - boolean pass = true; - - while (pass) { - String newPassword = screen.getPassSP(); - String newPasswordConfirm = screen.getPassSP(); - if (newPasswordConfirm.equals(newPassword)) { - - newCustomer.setPassword(newPassword); - pass = false; - } else { - screen.passwordMismatchSP(); - - } - } - - System.out.println("Please type Checking, Savings, Investments"); - openingAccount(screen, newCustomer); - - - -// System.out.println("What type of account do you want to open?\n 1 for Checking\n 2 for Savings\n 3 for Investment\n 0 to go back to login"); -// Integer testing = screen.getInput(); -// -// boolean openAcc = true; -// while (openAcc) -// switch (testing) { -// case 1: -// -// case 2: -// -// case 3: -// -// case 0: -// System.out.println("Thank you for using this ATM!"); -// openAcc = false; -// customerLogin(); -// break; -// default: -// testing = screen.getInput(); -// System.out.println("Please choose use 1 for checking, 2 for savings, 3 for investment, or 0 to exit to login screen."); -// break; -// } - } - - -// //enter password twice. check to see if they match - -// if (newPassword != newPasswordConfirm) { -// screen.passwordMismatchSP(); -// -// } else if (newPassword == newPasswordConfirm) { -// screen.initialAccountOpen(); -// } - //initial deposit - - - // path 2 -// prompts returning user for the necessary info -// username -// - - public void returningCustomer(){ - - Workflow screen = new Workflow(); - Customer mike = new Customer("Mike Ninh", - "msn", - "123", - new Account[]{new Savings(231412, 233)}); - - screen.returningUserSP(); - String userName; - String password; - if(mike.getUserName() != screen.getUserSP()){ - System.out.println("Username not found please try again"); - returningCustomer(); - }else{ - - } - } - -// screen.getUserSP(); -// //password, in while loop, which will kick user out if they fail three times -// screen.getPassSP(); - - - - - public void runEngine(){ - Workflow screen = new Workflow(); - - Account acct = new Savings(12, 34.0); - Account[] accts = new Account[1]; - accts[0] = acct; - Customer customer = new Customer("Hazel", "HD", "45", accts); - - //Starting screen - screen.initialWelcomeSP(); - //1 for new user, 2 for returning. this /just/ takes the number tho - screen.getInput(); - - //path 1 - //prompts new user for the necessary info - //name - screen.getNameSP(); - //username - screen.getUserSP(); - //enter password twice. check to see if they match - screen.getPassSP(); - screen.getPassSP(); - //initial deposit - screen.initialAccountOpen(); - - //path 2 - //prompts returning user for the necessary info - //username - screen.getUserSP(); - //password, in while loop, which will kick user out if they fail three times - screen.getPassSP(); - - - - //after the user has either been made or logged in we print the main menu - screen.mainMenuSP(customer); - - //switch statement for each option on the main menu - - //1 - //prints out "Which acct?" - screen.checkPromptSP(); - //The user enters which acct type - screen.enterAccount(); - //Depending on which acct type they enter, this checks the balance of that account - screen.checkResultSP(accts[0]); - - //2 - //prints out "Which acct?" - screen.transferPromptSP(); - //The user enters "from", then "to" - screen.enterAccount(); - screen.enterAccount(); - //there needs to be code in here that actually transfers the money - //print out "action performed successfully" and save it in transaction history - //this needs 2 acct inputs, the from and to, to save it to history - screen.completeResultSP(accts[0], accts[0]); - - //3 - //prints out "Which acct?" - screen.withdrawPromptSP(); - //The users enter which acct is being withdrawn from - screen.enterAccount(); - //there needs to be code in here that actually withdraws the money - //print out "action performed successfully" and save it in transaction history - //this needs 1 acct input to save it to history - screen.completeResultSP(accts[0]); - - //4 - //prints out "Which acct?" - screen.depositPromptSP(); - //The users enter which acct is being deposited to - screen.enterAccount(); - //there needs to be code in here that actually deposits the money - //print out "action performed successfully" and save it in transaction history - //this needs 1 acct input to save it to history - screen.completeResultSP(accts[0]); - - //5 - //"What kind of acct are you opening", takes a string - screen.openPrompt(); - //code in here that does the thing - - //6 - //"Which acct are you closing" - screen.closePrompt(); - //The user enters which acct to close - screen.enterAccount(); - //code in here that does the thing - - //7 - //all 7 does is print transaction history, the fun stuff is in other methods - screen.printHistory(); - - //8 - //all 8 does is log out - //take us back to the initial screen! - - - - } - -// public void withdrawal(Workflow screen, Customer customer) { -// boolean validAmount = true; -// screen.withdrawPromptSP(); -// -// Integer withdrawAccount = screen.enterAccount(); -// while(customer.getAccount(withdrawAccount) == null) { -// System.out.println("Account not on file"); -// withdrawAccount = screen.enterAccount(); -// } -// -// while (validAmount) { -// double withdrawalAmount = screen.amountPromptSP(); -// if (customer.getAccount(withdrawAccount).getBalance() > withdrawalAmount) { -// customer.getAccount(withdrawAccount).withdraw(withdrawalAmount); -// validAmount = false; -// } else System.out.println("Non sufficient funds"); -// } -// -// System.out.println(customer.getAccount(withdrawAccount).getBalance()); -// screen.completeResultSP(customer.getAccount(withdrawAccount)); -// } -// -// public void deposit(Workflow screen, Customer customer) { -// screen.depositPromptSP(); -// -// Integer depositAccount = screen.enterAccount(); -// while(customer.getAccount(depositAccount) == null) { -// System.out.println("Account not on file"); -// depositAccount = screen.enterAccount(); -// } -// -// double depositAmount = screen.amountPromptSP(); -// -// customer.getAccount(depositAccount).deposit(depositAmount); -// -// System.out.println(customer.getAccount(depositAccount).getBalance()); -// screen.completeResultSP(customer.getAccount(depositAccount)); -// } -// -// public void transfer(Workflow screen, Customer customer) { -// boolean validAmount = true; -// screen.transferPromptSP(); -// -// Integer withdrawAccount = screen.enterAccount(); -// while(customer.getAccount(withdrawAccount) == null) { -// System.out.println("Account not on file"); -// withdrawAccount = screen.enterAccount(); -// } -// -// Integer depositAccount = screen.enterAccount(); -// while(customer.getAccount(depositAccount) == null) { -// System.out.println("Account not on file"); -// depositAccount = screen.enterAccount(); -// } -// -// while (validAmount) { -// double transferAmount = screen.amountPromptSP(); -// if (customer.getAccount(withdrawAccount).getBalance() >= transferAmount) { -// customer.getAccount(withdrawAccount).withdraw(transferAmount); -// customer.getAccount(depositAccount).deposit(transferAmount); -// validAmount = false; -// } else System.out.println("Non sufficient funds"); -// } -// -// System.out.println(customer.getAccount(withdrawAccount).getBalance()); -// System.out.println(customer.getAccount(depositAccount).getBalance()); -// screen.completeResultSP(customer.getAccount(withdrawAccount), customer.getAccount(depositAccount)); -// } -public void closingAccount(Workflow screen, Customer customer) { - screen.closePrompt(); - Integer oldAccount=screen.enterAccount(); - Boolean validAccount=true; - while(customer.getAccount(oldAccount)==null){ - System.out.println("Account not on file"); - oldAccount=screen.enterAccount(); - } - while(validAccount){ - if(customer.getAccount(oldAccount).getBalance()==0) - { - customer.closeAccount(oldAccount); - break; + while (main.engineOn) { + ATM.runEngine(screen); } - else { - System.out.println("Must be empty"); - System.out.println("Remaining balance: $"+customer.getAccount(oldAccount).getBalance()); - break; - } - - } - System.out.println("User accounts: "+"\n"+customer.getAccountNumber()); - screen.completeResultsNoHistorySP(); -} - - public void openingAccount(Workflow screen,Customer customer) { - String uniqAccount = screen.openPrompt(); - boolean validType = true; - while (validType) { - if ("checking".equals(uniqAccount)) { - double firstCheckingDeposit = screen.amountPromptSP(); - Checking uniqChecking = Creator.createChecking(firstCheckingDeposit); - customer.addAccount(uniqChecking); - System.out.println(uniqChecking.getAccountNumber()); - System.out.println(uniqChecking.getBalance()); - System.out.println("User accounts: "+"\n"+customer.getAccountNumber()); - break; - } else if ("savings".equals(uniqAccount)) { - double firstSavingDeposit = screen.amountPromptSP(); - Checking uniqSaving = Creator.createChecking(firstSavingDeposit); - customer.addAccount(uniqSaving); - System.out.println(uniqSaving.getAccountNumber()); - System.out.println(uniqSaving.getBalance()); - System.out.println("User accounts: "+"\n"+customer.getAccountNumber()); - break; - } else if ("investment".equals(uniqAccount)) { - double firstInvestmentDeposit = screen.amountPromptSP(); - Checking uniqInvestment = Creator.createChecking(firstInvestmentDeposit); - customer.addAccount(uniqInvestment); - System.out.println(uniqInvestment.getAccountNumber()); - System.out.println(uniqInvestment.getBalance()); - System.out.println("User accounts: "+"\n"+customer.getAccountNumber()); - break; - } else - { - System.out.println("Not a valid entry. Please type in checking, savings, investment"); - uniqAccount = screen.openPrompt(); - } - - } - } } diff --git a/src/main/java/Motherboard.java b/src/main/java/Motherboard.java new file mode 100644 index 0000000..e6d684f --- /dev/null +++ b/src/main/java/Motherboard.java @@ -0,0 +1,258 @@ +public class Motherboard { + + public void runEngine(Workflow screen) { + customerLogin(screen); + } + + public void customerLogin(Workflow screen) { + screen.initialWelcomeSP(); + boolean test = true; + Integer input = screen.getInput(); + while (test) + switch (input) { + case 1: + createCustomer(); + test = false; + break; + case 2: + Customer currentUser = validateCredentials(screen); + if (currentUser == null) { + System.out.println("Sorry cannot log you in at this time"); + test = false; + break; + } + returningCustomer(screen, currentUser); + test = false; + break; + default: + input = screen.getInput(); + System.out.println("Please choose 1 for new customer or 2 for returning customer."); + break; + } + } + + public Customer validateCredentials(Workflow screen) { + String newUsername = screen.getUserSP(); + int counter = 0; + int tries = 3; + + while(Database.getCustomerByUsername(newUsername) == null) { + System.out.println("Account not on file"); + newUsername = screen.getUserSP(); + } + + Customer currentUser = Database.getCustomerByUsername(newUsername); + + while(counter < 3) { + String userPass = screen.getPassSP(); + if (currentUser.getPassword().equals(userPass)) { + return currentUser; + } else + counter++; + tries--; + System.out.println(String.format("Invalid password: Tries left - %s", tries)); + } + + return null; + } + + public void createCustomer() { + Workflow screen = new Workflow(); + Customer newCustomer = Creator.createCustomer(null, null, null, null); + String newCustomerName = screen.getCustomerNameSP(); + newCustomer.setCustomerName(newCustomerName); + screen.newUserSP(); + String newUsername = screen.getUserSP(); + boolean user = true; + + while (user) + if (Database.getCustomerByUsername(newUsername) != null) { + screen.usernameTakenSP(); + newUsername = screen.getUserSP(); + } else { + newCustomer.setUserName(newUsername); + user = false; + } + + boolean pass = true; + while (pass) { + String newPassword = screen.getPassSP(); + String newPasswordConfirm = screen.getPassSP(); + if (newPasswordConfirm.equals(newPassword)) { + newCustomer.setPassword(newPassword); + pass = false; + } else { + screen.passwordMismatchSP(); + } + } + + System.out.println("Which type of account would you like to open:\nChecking\nSavings\nInvestment"); + openingAccount(screen, newCustomer); + Database.addCustomer(newCustomer); + } + + + public void returningCustomer(Workflow screen, Customer customer){ + boolean currentlyUsing = true; + + while(currentlyUsing) { + screen.mainMenuSP(customer); + Integer input = screen.getInput(); + switch (input) { + case 1: + check(screen, customer); + break; + case 2: + transfer(screen, customer); + break; + case 3: + withdrawal(screen, customer); + break; + case 4: + deposit(screen, customer); + break; + case 5: + openingAccount(screen, customer); + break; + case 6: + closingAccount(screen, customer); + break; + case 7: + history(screen); + break; + case 8: + screen.logOutSP(); + currentlyUsing = false; + } + } + } + + public void withdrawal(Workflow screen, Customer customer) { + boolean validAmount = true; + screen.withdrawPromptSP(); + + Integer withdrawAccount = screen.enterAccount(); + while(customer.getAccount(withdrawAccount) == null) { + System.out.println("Account not on file"); + withdrawAccount = screen.enterAccount(); + } + + while (validAmount) { + double withdrawalAmount = screen.amountPromptSP(); + if (customer.getAccount(withdrawAccount).getBalance() > withdrawalAmount) { + customer.getAccount(withdrawAccount).withdraw(withdrawalAmount); + validAmount = false; + } else System.out.println("Non sufficient funds"); + } + + screen.completeResultSP(customer.getAccount(withdrawAccount)); + } + + public void deposit(Workflow screen, Customer customer) { + screen.depositPromptSP(); + + Integer depositAccount = screen.enterAccount(); + while(customer.getAccount(depositAccount) == null) { + System.out.println("Account not on file"); + depositAccount = screen.enterAccount(); + } + + double depositAmount = screen.amountPromptSP(); + + customer.getAccount(depositAccount).deposit(depositAmount); + screen.completeResultSP(customer.getAccount(depositAccount)); + } + + public void transfer(Workflow screen, Customer customer) { + boolean validAmount = true; + screen.transferPromptSP(); + + Integer withdrawAccount = screen.enterAccount(); + while(customer.getAccount(withdrawAccount) == null) { + System.out.println("Account not on file"); + withdrawAccount = screen.enterAccount(); + } + + Integer depositAccount = screen.enterAccount(); + while(customer.getAccount(depositAccount) == null) { + System.out.println("Account not on file"); + depositAccount = screen.enterAccount(); + } + + while (validAmount) { + double transferAmount = screen.amountPromptSP(); + if (customer.getAccount(withdrawAccount).getBalance() >= transferAmount) { + customer.getAccount(withdrawAccount).withdraw(transferAmount); + customer.getAccount(depositAccount).deposit(transferAmount); + validAmount = false; + } else System.out.println("Non sufficient funds"); + } + screen.completeResultSP(customer.getAccount(withdrawAccount), customer.getAccount(depositAccount)); + } + public void closingAccount(Workflow screen, Customer customer) { + screen.closePrompt(); + Integer oldAccount=screen.enterAccount(); + Boolean validAccount=true; + while(customer.getAccount(oldAccount)==null){ + System.out.println("Account not on file"); + oldAccount=screen.enterAccount(); + } + while(validAccount){ + if(customer.getAccount(oldAccount).getBalance()==0) { + customer.closeAccount(oldAccount); + break; + } + else { + System.out.println("Account balance must be ZERO.\nRemaining balance: $"+customer.getAccount(oldAccount).getBalance()); + break; + } + } + screen.completeResultsNoHistorySP(); + } + + public void openingAccount(Workflow screen,Customer customer) { + String uniqAccount = screen.openPrompt(); + boolean validType = true; + while (validType) { + if ("checking".equals(uniqAccount)) { + double firstCheckingDeposit = screen.amountPromptSP(); + Checking uniqChecking = Creator.createChecking(firstCheckingDeposit); + customer.addAccount(uniqChecking); + System.out.println("User accounts: "+"\n"+customer.getAccountNumber()); + break; + } else if ("savings".equals(uniqAccount)) { + double firstSavingDeposit = screen.amountPromptSP(); + Checking uniqSaving = Creator.createChecking(firstSavingDeposit); + customer.addAccount(uniqSaving); + System.out.println("User accounts: "+"\n"+customer.getAccountNumber()); + break; + } else if ("investment".equals(uniqAccount)) { + double firstInvestmentDeposit = screen.amountPromptSP(); + Checking uniqInvestment = Creator.createChecking(firstInvestmentDeposit); + customer.addAccount(uniqInvestment); + System.out.println("User accounts: "+"\n"+customer.getAccountNumber()); + break; + } else { + System.out.println("Not a valid entry. Please type in checking, savings, investment"); + uniqAccount = screen.openPrompt(); + } + } + } + + public void check(Workflow screen, Customer customer){ + screen.checkPromptSP(); + while(true) { + try { + Integer acctNumber = screen.enterAccount(); + screen.checkResultSP(customer.getAccount(acctNumber)); + break; + } catch (Exception e) { + screen.errorSP(); + } + } + } + + public void history(Workflow screen){ + screen.printHistory(); + } +} diff --git a/src/main/java/Workflow.java b/src/main/java/Workflow.java index 3110984..f24ef03 100644 --- a/src/main/java/Workflow.java +++ b/src/main/java/Workflow.java @@ -97,28 +97,28 @@ public void checkResultSP(Account account){ public void withdrawPromptSP(){ d.currentDisplaySP("What account do you want to withdraw from?"); - lastAction = " withdrawn from "; + lastAction = "withdrawn from"; } public void depositPromptSP(){ d.currentDisplaySP("What account do you want to deposit into?"); - lastAction = " deposited into "; + lastAction = "deposited into"; } public void transferPromptSP(){ d.currentDisplaySP("What accounts do you want to transfer from and to?"); - lastAction = " transferred to "; + lastAction = "transferred from"; } public Double amountPromptSP(){ //try catch - lastAmount = c.getDoubleInput("How much?"); + lastAmount = c.getDoubleInput("Transaction amount:"); return lastAmount; } public void completeResultSP(Account account){ d.currentDisplaySP("Action performed successfully.\n"); - d.addToTransactionHistory("$" + lastAmount + lastAction + "account #" + account.getAccountNumber()); + d.addToTransactionHistory(String.format("$ %s %s account #%s\n", lastAmount, lastAction, account.getAccountNumber())); } public void completeResultSP(Account account1, Account account2){ From 45e1d0c1e82ffc2dd4eec410b3b9d596d727bd38 Mon Sep 17 00:00:00 2001 From: xyuan04 <78838190+xyuan04@users.noreply.github.com> Date: Sun, 14 Mar 2021 23:39:08 -0400 Subject: [PATCH 34/35] added check account numbers for motherboard + minor fixes --- src/main/java/Account.java | 2 +- src/main/java/Customer.java | 4 ++-- src/main/java/Main.java | 2 ++ src/main/java/Motherboard.java | 7 +++++++ src/main/java/Workflow.java | 2 +- src/main/test/java/CustomerTest.java | 8 ++++---- 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/Account.java b/src/main/java/Account.java index 2bb2c48..a9a521a 100644 --- a/src/main/java/Account.java +++ b/src/main/java/Account.java @@ -16,7 +16,7 @@ public double getBalance() { } public double withdraw(double amount) { - if (balance >= amount) { + if (balance >= amount && amount >= 0) { balance -= amount; } return balance; diff --git a/src/main/java/Customer.java b/src/main/java/Customer.java index e31b69b..02bbf6b 100644 --- a/src/main/java/Customer.java +++ b/src/main/java/Customer.java @@ -39,9 +39,9 @@ public void setPassword(String password){ } public String getAccountNumber() { - String accountNumbers = ""; + String accountNumbers = "Accounts: \n"; for(int i = 0; i < accounts.size(); i++) { - accountNumbers += String.format("%s\n", accounts.get(i).getAccountNumber()); + accountNumbers += String.format("%d : %s\n", i+1, accounts.get(i).getAccountNumber()); } return accountNumbers; } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index e58a335..3e527de 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -5,6 +5,8 @@ public class Main { private boolean engineOn = true; public static void main(String[] args) { + Main main = new Main(); + Motherboard ATM = new Motherboard(); Workflow screen = new Workflow(); Customer xiong = Creator.createCustomer("xiong", "xyuan", "zipcode", new Checking(100, 1500), new Savings(1000, 2500), new Investment(10000, 6000)); Customer mike = Creator.createCustomer("mike", "ninh", "zipcode", new Checking(101, 1500), new Savings(1001, 2500), new Investment(10001, 6000)); diff --git a/src/main/java/Motherboard.java b/src/main/java/Motherboard.java index e6d684f..52d7c42 100644 --- a/src/main/java/Motherboard.java +++ b/src/main/java/Motherboard.java @@ -99,6 +99,9 @@ public void returningCustomer(Workflow screen, Customer customer){ screen.mainMenuSP(customer); Integer input = screen.getInput(); switch (input) { + case 0: + checkAccountNumbers(customer); + break; case 1: check(screen, customer); break; @@ -239,6 +242,10 @@ public void openingAccount(Workflow screen,Customer customer) { } } + public void checkAccountNumbers(Customer customer) { + System.out.println(customer.getAccountNumber()); + } + public void check(Workflow screen, Customer customer){ screen.checkPromptSP(); while(true) { diff --git a/src/main/java/Workflow.java b/src/main/java/Workflow.java index f24ef03..afef61c 100644 --- a/src/main/java/Workflow.java +++ b/src/main/java/Workflow.java @@ -72,7 +72,7 @@ public void initialAccountOpen(){ public void mainMenuSP(Customer customer){ - d.currentDisplaySP("Welcome, " + customer.getCustomerName() + "! What do you want to do?\nEnter 1 to check balance\t\t\t\tEnter 2 to transfer\nEnter 3 to withdraw\t\t\t\t\t\tEnter 4 to deposit\nEnter 5 to open a new account\t\t\tEnter 6 to close an account\nEnter 7 to print transaction history\tEnter 8 to log out"); + d.currentDisplaySP("Welcome, " + customer.getCustomerName() + "! What do you want to do?\n\n\t\t\tEnter 0 to check account number\nEnter 1 to check balance\t\t\t\tEnter 2 to transfer\nEnter 3 to withdraw\t\t\t\t\t\tEnter 4 to deposit\nEnter 5 to open a new account\t\t\tEnter 6 to close an account\nEnter 7 to print transaction history\tEnter 8 to log out\n"); } diff --git a/src/main/test/java/CustomerTest.java b/src/main/test/java/CustomerTest.java index f27f1aa..9472ba3 100644 --- a/src/main/test/java/CustomerTest.java +++ b/src/main/test/java/CustomerTest.java @@ -17,7 +17,7 @@ public void customerConstuctor() { String actualName = xiong.getCustomerName(); String actualUserName = xiong.getUserName(); String actualPassword = xiong.getPassword(); - String account = "24231\n" + "111\n"; + String account = "Accounts: \n1 : 24231\n2 : 111\n"; String actualAccount = xiong.getAccountNumber(); // : Then @@ -134,7 +134,7 @@ public void getAccountNumber() { Account investAccount = new Investment(111, 50000); Account[] accounts = new Account[]{checkingAccount, savingsAccount, investAccount}; // : When - String account = "32563\n" + "992223\n" + "111\n"; + String account = "Accounts: \n1 : 32563\n" + "2 : 992223\n" + "3 : 111\n"; Customer wayne = new Customer(customerName, userName, password, accounts); String actualAccount = wayne.getAccountNumber(); @@ -173,7 +173,7 @@ public void testCloseAccountWithBalance() { Account investAccount = new Investment(111, 50000); Account[] accounts = new Account[]{checkingAccount, savingsAccount, investAccount}; // : When - String account = "32563\n" + "992223\n" + "111\n"; + String account = "Accounts: \n1 : 32563\n" + "2 : 992223\n" + "3 : 111\n"; Customer wayne = new Customer(customerName, userName, password, accounts); wayne.getAccount(111).withdraw(10000); wayne.closeAccount(111); @@ -195,7 +195,7 @@ public void testCloseAccountWithNoBalance() { Account investAccount = new Investment(111, 50000); Account[] accounts = new Account[]{checkingAccount, savingsAccount, investAccount}; // : When - String account = "32563\n" + "992223\n"; + String account = "Accounts: \n1 : 32563\n" + "2 : 992223\n"; Customer wayne = new Customer(customerName, userName, password, accounts); wayne.getAccount(111).withdraw(50000); wayne.closeAccount(111); From 66928d40f6f17fa8bd5e4ac196f0941c7f8ee1ac Mon Sep 17 00:00:00 2001 From: MNinh <78838228+MNinh@users.noreply.github.com> Date: Mon, 15 Mar 2021 08:44:03 -0400 Subject: [PATCH 35/35] finalized ATM --- src/main/java/Motherboard.java | 64 +++++++++++++++++++++++++++++++--- src/main/java/Workflow.java | 46 ++++++++++++++---------- 2 files changed, 86 insertions(+), 24 deletions(-) diff --git a/src/main/java/Motherboard.java b/src/main/java/Motherboard.java index 52d7c42..a2599aa 100644 --- a/src/main/java/Motherboard.java +++ b/src/main/java/Motherboard.java @@ -1,3 +1,5 @@ +import java.util.ArrayList; + public class Motherboard { public void runEngine(Workflow screen) { @@ -20,7 +22,7 @@ public void customerLogin(Workflow screen) { System.out.println("Sorry cannot log you in at this time"); test = false; break; - } + }else if(currentUser.equals("0")){customerLogin(screen);} returningCustomer(screen, currentUser); test = false; break; @@ -32,10 +34,13 @@ public void customerLogin(Workflow screen) { } public Customer validateCredentials(Workflow screen) { + screen.returningUserSP(); String newUsername = screen.getUserSP(); int counter = 0; int tries = 3; + if(newUsername.equals("0")){customerLogin(screen);} + while(Database.getCustomerByUsername(newUsername) == null) { System.out.println("Account not on file"); newUsername = screen.getUserSP(); @@ -45,24 +50,30 @@ public Customer validateCredentials(Workflow screen) { while(counter < 3) { String userPass = screen.getPassSP(); + if(userPass.equals("0")){customerLogin(screen);} if (currentUser.getPassword().equals(userPass)) { return currentUser; } else + counter++; tries--; System.out.println(String.format("Invalid password: Tries left - %s", tries)); } - return null; } public void createCustomer() { Workflow screen = new Workflow(); Customer newCustomer = Creator.createCustomer(null, null, null, null); + + screen.newCustomerNameSP(); String newCustomerName = screen.getCustomerNameSP(); newCustomer.setCustomerName(newCustomerName); + if(newCustomerName.equals("0")){customerLogin(screen);} + screen.newUserSP(); String newUsername = screen.getUserSP(); + if(newUsername.equals("0")){customerLogin(screen);} boolean user = true; while (user) @@ -78,10 +89,11 @@ public void createCustomer() { while (pass) { String newPassword = screen.getPassSP(); String newPasswordConfirm = screen.getPassSP(); + if(newPassword.equals("0") || newPasswordConfirm.equals("0")){customerLogin(screen);} if (newPasswordConfirm.equals(newPassword)) { newCustomer.setPassword(newPassword); pass = false; - } else { + }else { screen.passwordMismatchSP(); } } @@ -91,7 +103,6 @@ public void createCustomer() { Database.addCustomer(newCustomer); } - public void returningCustomer(Workflow screen, Customer customer){ boolean currentlyUsing = true; @@ -124,8 +135,12 @@ public void returningCustomer(Workflow screen, Customer customer){ history(screen); break; case 8: + wireTransfer(screen, customer); + break; + case 9: screen.logOutSP(); currentlyUsing = false; + break; } } } @@ -206,7 +221,8 @@ public void closingAccount(Workflow screen, Customer customer) { break; } else { - System.out.println("Account balance must be ZERO.\nRemaining balance: $"+customer.getAccount(oldAccount).getBalance()); + System.out.println("Account balance must be ZERO.\n" + + "Remaining balance: $" +customer.getAccount(oldAccount).getBalance()); break; } } @@ -262,4 +278,42 @@ public void check(Workflow screen, Customer customer){ public void history(Workflow screen){ screen.printHistory(); } + + public void wireTransfer(Workflow screen, Customer customer) { + + Integer withdrawAccount = screen.enterAccount(); + while(customer.getAccount(withdrawAccount) == null) { + System.out.println("Account not on file"); + withdrawAccount = screen.enterAccount(); + } + + System.out.println("please enter the username you want to transfer to"); + String toTransfer = screen.getUserSP2(); + + while(Database.getCustomerByUsername(toTransfer) == null) { + System.out.println("Account not on file"); + toTransfer= screen.getUserSP2(); + } + + Customer transferUser = Database.getCustomerByUsername(toTransfer); + + boolean validAmount = true; + screen.transfer2UserPromptSP(); + + Integer depositAccount = screen.enterAccount(); + while(transferUser.getAccount(depositAccount) == null) { + System.out.println("Account not on file"); + depositAccount = screen.enterAccount(); + } + + while (validAmount) { + double transferAmount = screen.amountPromptSP(); + if (customer.getAccount(withdrawAccount).getBalance() >= transferAmount) { + customer.getAccount(withdrawAccount).withdraw(transferAmount); + transferUser.getAccount(depositAccount).deposit(transferAmount); + validAmount = false; + } else System.out.println("Non sufficient funds"); + } + screen.completeResultSP(customer.getAccount(withdrawAccount), transferUser.getAccount(depositAccount)); + } } diff --git a/src/main/java/Workflow.java b/src/main/java/Workflow.java index afef61c..6ed9df9 100644 --- a/src/main/java/Workflow.java +++ b/src/main/java/Workflow.java @@ -17,7 +17,7 @@ public void errorSP(){ } public void initialWelcomeSP(){ - d.currentDisplaySP("Welcome to the ATM! Are you a new or returning user?\nEnter 1 for new, 2 for returning, 0 to exit atm."); + d.currentDisplaySP("\nWelcome to the ATM!\nATM maintained by Xiong, Mike, Hazel, and Lena\n\nAre you a new or returning user?\nEnter 1 for new, 2 for returning."); } public Integer getInput(){ @@ -28,10 +28,10 @@ public Integer getInput(){ //include input for customername public void newCustomerNameSP(){ - d.currentDisplaySP("Enter your Name"); + d.currentDisplaySP("Enter 0 to return back to home page."); } public String getCustomerNameSP(){ - return c.getStringInput(("Your name here")); + return c.getStringInput(("\nEnter your name here")); } public void usernameTakenSP(){ @@ -40,22 +40,26 @@ public void usernameTakenSP(){ //initial opening of an account + deposit. double and string public void newUserSP(){ - d.currentDisplaySP("Input your username, then password twice, or type one lowercase x now to cancel."); + d.currentDisplaySP("Input your username, then password twice.\nEnter 0 to return back to home page"); } public void passwordMismatchSP(){ - d.currentDisplaySP("Passwords do not match. Please try again."); + d.currentDisplaySP("\nPasswords do not match. Please try again."); } public void returningUserSP(){ - d.currentDisplaySP("Input your username, then password, or type one lowercase x now to cancel."); + d.currentDisplaySP("\nInput your username, then password.\nEnter 0 to return back to home page."); } public String getUserSP(){ - String middleMan = c.getStringInput("Enter username:"); + String middleMan = c.getStringInput("\nEnter username:"); d.setTransactionHistory("History of user " + middleMan + "\n"); return middleMan; } + public String getUserSP2(){ + return c.getStringInput("\nEnter username:"); + + } public String getPassSP(){ return c.getStringInput("Enter password:"); @@ -72,11 +76,15 @@ public void initialAccountOpen(){ public void mainMenuSP(Customer customer){ - d.currentDisplaySP("Welcome, " + customer.getCustomerName() + "! What do you want to do?\n\n\t\t\tEnter 0 to check account number\nEnter 1 to check balance\t\t\t\tEnter 2 to transfer\nEnter 3 to withdraw\t\t\t\t\t\tEnter 4 to deposit\nEnter 5 to open a new account\t\t\tEnter 6 to close an account\nEnter 7 to print transaction history\tEnter 8 to log out\n"); + d.currentDisplaySP("Welcome, " + customer.getCustomerName() + "! What do you want to do?\n" + + "\n" + + "Enter 0 to check account number\t\t\t\t\tEnter 1 to check balance\n" + + "Enter 2 to transfer\t\t\t\t\t\t\t\tEnter 3 to withdraw\n" + + "Enter 4 to deposit\t\t\t\t\t\t\t\tEnter 5 to open a new account\n" + + "Enter 6 to close an account\t\t\t\t\t\tEnter 7 to print transaction history\n" + + "Enter 8 to transfer to a different user\t\t\tEnter 9 to log out\n"); } - - public int enterAccount(){ return c.getIntegerInput("Enter an account:"); } @@ -93,21 +101,24 @@ public void checkResultSP(Account account){ d.currentDisplaySP("Your account's current balance is " + account.getBalance()); } - - public void withdrawPromptSP(){ d.currentDisplaySP("What account do you want to withdraw from?"); - lastAction = "withdrawn from"; + lastAction = " withdrawn from "; } public void depositPromptSP(){ d.currentDisplaySP("What account do you want to deposit into?"); - lastAction = "deposited into"; + lastAction = " deposited into "; } public void transferPromptSP(){ d.currentDisplaySP("What accounts do you want to transfer from and to?"); - lastAction = "transferred from"; + lastAction = " transferred from "; + } + + public void transfer2UserPromptSP(){ + d.currentDisplaySP("What account do you want to transfer to?"); + lastAction = " transferred from "; } public Double amountPromptSP(){ @@ -130,8 +141,6 @@ public void completeResultsNoHistorySP(){ d.currentDisplaySP("Action performed successfully.\n"); } - - public String openPrompt(){ return c.getStringInputNotCaseSensitive("What kind of account do you want to open?"); } @@ -144,11 +153,10 @@ public void printHistory(){ d.printTransactionHistory(); } - - public void logOutSP(){ d.currentDisplaySP("Thank you for your business."); d.setTransactionHistory(""); } } +