diff --git a/pom.xml b/pom.xml index 9901415..1012f0d 100644 --- a/pom.xml +++ b/pom.xml @@ -8,5 +8,14 @@ project-2-atm 1.0-SNAPSHOT + + + + junit + junit + 4.12 + + + \ 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..a2bd8bd --- /dev/null +++ b/src/main/java/Account.java @@ -0,0 +1,76 @@ + +public abstract class Account { + + private int acctnumber; + private double balance; + + + public Account(){ + this.acctnumber = AccountWarehouse.getAccounts().size(); + this.balance = 0; + //nextAvailableAcctNumber++; + } + + public Account(double initial_deposit){ + this(); + this.balance = initial_deposit; + } + + public void setAcctNumber(int acctnumber) { + this.acctnumber = acctnumber; + } + + + public int getAcctNumber() { + return acctnumber; + } + + + public void setBalance(double balance) { + this.balance = balance; + } + + + public double getBalance() { + return balance; + } + + public String deposit(double deposit) { + + balance += deposit; + + return "Your new balance is $" + String.format("%,.2f", balance); + + } + + public String withdrawl(double withdrawl){ + + balance -= withdrawl; + + return "Your new balance is $" + String.format("%,.2f", balance); + + } + + public String transfer(Account toAccount, double amount){ + + balance -= amount; + + toAccount.balance += amount; + + + return "Transfer complete. New 'from' balance is $" + String.format("%,.2f", this.getBalance()) + ". Your new 'to' balance is $" + String.format("%,.2f", toAccount.getBalance())+"."; + } + +// @Override +// public String toString(){ +// return "Account# " + this.acctnumber; + + +} + + + + + + + diff --git a/src/main/java/AccountWarehouse.java b/src/main/java/AccountWarehouse.java new file mode 100644 index 0000000..4f29055 --- /dev/null +++ b/src/main/java/AccountWarehouse.java @@ -0,0 +1,35 @@ +import java.util.ArrayList; + +public class AccountWarehouse { + private static final ArrayList accounts = new ArrayList(); + + private AccountWarehouse(){ + + } + + public static ArrayList getAccounts() { + return accounts; + } + + public static Account findAccountByAcctNumber(int acctNumber) { + + for (int i = 0; i < accounts.size(); i++) { + if (accounts.get(i).getAcctNumber() == acctNumber) { + return accounts.get(i); + } + }return null; + } + + public static void addAccount(Account account){ + accounts.add(account); + } + + public static void removeAccount(Account account){ + accounts.remove(account); + + } + + +} + + diff --git a/src/main/java/Checking.java b/src/main/java/Checking.java new file mode 100644 index 0000000..7b732f1 --- /dev/null +++ b/src/main/java/Checking.java @@ -0,0 +1,10 @@ +public class Checking extends Account { + + public Checking(){ + super(); + } + + public Checking(double initial_deposit){ + super(initial_deposit); + } +} diff --git a/src/main/java/Customer.java b/src/main/java/Customer.java new file mode 100644 index 0000000..ca04750 --- /dev/null +++ b/src/main/java/Customer.java @@ -0,0 +1,120 @@ +import java.util.ArrayList; + +public class Customer { + + private String username; + private String password; + private ArrayList customerAccounts; + + + public Customer(){ + this.username = "UNASSIGNED"; + this.password = "PASSWORD"; + this.customerAccounts = new ArrayList(); + this.customerAccounts.add(new Checking()); + } + + + public Customer(String username){ + this(); + this.username = username; + + } + + public Customer(String username, String password){ + this(username); + this.password = password; + } + + + public void setPassword(String password) { + this.password = password; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public String getUsername() { + return username; + } + + public ArrayList getCustomerAccounts() { + return customerAccounts; + } + + public void openAccount(){ + Account checking = new Checking(); + customerAccounts.add(checking); + AccountWarehouse.addAccount(checking); + + + } + + public Account lookupAcctByNumber(int accountnumber){ + for(int i = 0; i getAccount(int index){ +// +// return AccountList; +// +// }; +// + +// +// public void closeAllAccounts(){ +// +// } + + + + + + +// public ArrayList[] getAccountList() { +// return AccountList; +// } + + + + +} diff --git a/src/main/java/CustomerWarehouse.java b/src/main/java/CustomerWarehouse.java new file mode 100644 index 0000000..83bfda6 --- /dev/null +++ b/src/main/java/CustomerWarehouse.java @@ -0,0 +1,33 @@ +import java.util.ArrayList; + +public class CustomerWarehouse { + + private static final ArrayList customers = new ArrayList(); + + + + public static ArrayList getCustomers() { + return customers; + } + + public static Customer lookupCustomer(String username) { +// for(Customer currentelement: customers) { +// if (customers.get(currentelement).getUsername() == username) { +// return customers.get(currentelement); +// } +// } + for (int i = 0; i < customers.size(); i++) { + if (customers.get(i).getUsername() == username) { + return customers.get(i); + } + + }return null; + } + public static void addCustomer(Customer customer){ + customers.add(customer); + } + + public static void removeCustomer(Customer customer){ + customers.remove(customer); + } +} diff --git a/src/main/java/DoTheThing.java b/src/main/java/DoTheThing.java new file mode 100644 index 0000000..ee11d62 --- /dev/null +++ b/src/main/java/DoTheThing.java @@ -0,0 +1,18 @@ +//public class DoTheThing { +// +// public static void main(String[] args) { +// +// System.out.println("Got an account with us? y/n"); +// System.out.println("Want one? y/n"); +// +// createUser(); +// addtoAllTheUsers(); +// +// System.out.println("What do you want to do with your account?"); +// +// showMainMenu(); +// // 1. Deposit 2. Withdraw 3. Get Balance 4. Add Account 5. Close Account +// +// } +// +//} diff --git a/src/main/java/Investment.java b/src/main/java/Investment.java new file mode 100644 index 0000000..edc913b --- /dev/null +++ b/src/main/java/Investment.java @@ -0,0 +1,10 @@ +public class Investment extends Account { + + public Investment(){ + super(); + } + + public Investment(double initial_deposit){ + super(initial_deposit); + } +} 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){ - + } } diff --git a/src/main/java/Savings.java b/src/main/java/Savings.java new file mode 100644 index 0000000..b1e16f5 --- /dev/null +++ b/src/main/java/Savings.java @@ -0,0 +1,10 @@ +public class Savings extends Account { + + public Savings(){ + super(); + } + + public Savings(double initial_deposit){ + super(initial_deposit); + } +} diff --git a/src/main/test/AccountWarehouseTest.java b/src/main/test/AccountWarehouseTest.java new file mode 100644 index 0000000..57eaec7 --- /dev/null +++ b/src/main/test/AccountWarehouseTest.java @@ -0,0 +1,59 @@ +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; + +public class AccountWarehouseTest { + + + @Test + public void findAccountByAcctNumber(){ + //given + // ArrayList accounts = AccountWarehouse.getAccounts(); + Account expected = new Savings(); + AccountWarehouse.addAccount(expected); + + //when + Account actual = AccountWarehouse.findAccountByAcctNumber(expected.getAcctNumber()); + + //then + Assert.assertEquals(expected,actual); + + } + + + @Test + public void addAccountTest(){ + //given + Account expected = new Savings(); + + //when + AccountWarehouse.addAccount(expected); + + //then + Account actual = AccountWarehouse.findAccountByAcctNumber(expected.getAcctNumber()); + + + Assert.assertEquals(expected, actual); + + } + + @Test + public void removeAccountTest(){ + + //given + Account expected = null; + Account acctnumber1 = new Savings(); + + //when + AccountWarehouse.addAccount(acctnumber1); + AccountWarehouse.removeAccount(acctnumber1); + Account actual = AccountWarehouse.findAccountByAcctNumber(acctnumber1.getAcctNumber()); + + + //then + Assert.assertEquals(expected, actual); + + } + +} diff --git a/src/main/test/CheckingTest.java b/src/main/test/CheckingTest.java new file mode 100644 index 0000000..d3bc71c --- /dev/null +++ b/src/main/test/CheckingTest.java @@ -0,0 +1,88 @@ +import org.junit.Assert; +import org.junit.Test; + +public class CheckingTest { + + @Test + public void CheckingTest(){ + + //check constructors + + + //given + Checking checking = new Checking(50000); + Checking checking2 = new Checking(); + double expected = 50000; + int expected_account = 1; + int expected_2nd_account = 2; + + //when + double actual = checking.getBalance(); + int actual_account = checking.getAcctNumber(); + int actual_2nd_account = checking2.getAcctNumber(); + + //then + Assert.assertTrue("check constructor", expected == actual); + Assert.assertEquals("check account number", expected_account, actual_account); + Assert.assertEquals("check account number", expected_2nd_account, actual_2nd_account); + + } + + @Test + public void depositTest(){ + + //given + Checking checking = new Checking(); + String expected = "Your new balance is $11,000.00"; + + //when + checking.setBalance(6000); + String actual = checking.deposit(5000); + + //then + Assert.assertEquals(expected,actual); + + + } + + @Test + public void withdrawlTest(){ + + Checking checking = new Checking(); + String expected = "Your new balance is $0.23"; + + checking.setBalance(4000.23); + String actual = checking.withdrawl(4000); + + Assert.assertEquals(expected, actual); + } + + @Test + public void transferTest(){ + + Checking fromChecking = new Checking(3500); + Savings toSavings = new Savings(500); + + String expected = "Transfer complete. New 'from' balance is $1,500.00. " + + "Your new 'to' balance is $2,500.00."; + + String actual = fromChecking.transfer(toSavings, 2000); + + Assert.assertEquals(expected, actual); + } + + @Test + public void toStringTest(){ + Savings savings = new Savings(); + String expected = "Account# 1"; + + String actual = savings.toString(); + + Assert.assertEquals(expected, actual); + + + } + + + +} \ No newline at end of file diff --git a/src/main/test/CustomerTest.java b/src/main/test/CustomerTest.java new file mode 100644 index 0000000..3106c48 --- /dev/null +++ b/src/main/test/CustomerTest.java @@ -0,0 +1,189 @@ +import org.junit.Assert; +import org.junit.Test; +import sun.util.resources.cldr.so.CurrencyNames_so; + +import java.util.ArrayList; + +public class CustomerTest { + + @Test + public void CustomerTest(){ + + + //given + Customer customer = new Customer("luvmykitty47", "fluffy"); + String expected_username = "luvmykitty47"; + String expected_password = "fluffy"; + + //when + String actual_username = customer.getUsername(); + String actual_password = customer.getPassword(); + + + //then + Assert.assertEquals("test constructor username", expected_username, actual_username); + Assert.assertEquals("test constructor password", expected_password, actual_password); + } + + @Test + public void openAccount(){ + //given + Customer customer = new Customer(); + int expected = customer.getCustomerAccounts().size() + 1; + + //when + customer.openAccount(); + + //Account actual = customer.lookupAcctByNumber(); + //when you realize that you're trying to figure out how declare an "expected" object before + //it's been created, it's time to go to bed. + int actual =customer.getCustomerAccounts().size(); + + //then + Assert.assertEquals(expected,actual); + + } + + @Test + public void lookupAccountByNumber(){ + //given + Customer customer = new Customer(); + Account checking = new Checking(); + int expected = checking.getAcctNumber(); + + customer.getCustomerAccounts().add(checking); + + //when + Account lookedUpAccount = customer.lookupAcctByNumber(expected); + int actual = lookedUpAccount.getAcctNumber(); + + //then + Assert.assertEquals(expected,actual); + + } + +// @Test +// public void getCustomerAccountsTest(){ +// //given +// Customer customer = new Customer(); +// ArrayList customerAccounts = new +// //when +// +// //then +// } +// +// +// @Test +// public void getAccountByIndex(){ +// //given +// Customer customer = new Customer(); +// String expected = "Account# 1"; +// +// //when +// String actual = customer.getAccountByIndex(0); +// +// //then +// Assert.assertEquals(expected, actual); +// +// +// } +// +// +// @Test +// public void addOneAccountTest(){ +// //given +// Customer customer = new Customer(); +// String expected = "You now have 3 accounts: Account# 1, Account# 2, Account# 3."; +// +// //when +// customer.addOneAccount(); //add account 2 +// customer.addOneAccount(); //add account 3 +// +// +// String actual = "You now have " + customer.getNumberOfAccounts() + " accounts: "; // + customer.listAllAccounts() +// +// //then +// Assert.assertEquals(expected, actual); +// +// +// } + +// @Test +// public void getAccountObjectByIndex(){ +// //given +// Customer customer = new Customer(); +// Account expected = new Checking(); +// +// //when +// Account actual = customer.getAccountObjectByIndex(0); +// +// Assert.assertEquals(expected,actual); + + + + + } + +// @Test +// public void getAccountList(){ +// //given +// Customer customer = new Customer(); +// String expected = "Some weird string of objects or hashes"; +// +// //when +// Objec = customer.getAccountList(); +// +// //then +// Assert.assertEquals(expected, actual); +// } + + +// @Test +// public void getOneAccount(){ +// //given +// Customer customer = new Customer(); +// String expected = "Account 0"; +// +// //when +// String expected = customer.ArrayList.get(0) +// } +// +// @Test +// public void addOneAccount(){ +// //given +// Customer customer = new Customer(); +// String expected = "Your new checking account 'gpatselas2' is now available."; +// +// //when +// String actual = customer.addOneAccount(); +// +// +// //then +// Assert.assertEquals(expected,actual); +// +// } + + //moved deposit to account class + +// @Test +// public void depositTest(){ +// +// //given +// Customer acustomer = new Customer(); +// String expected = "You're new balance is 5000."; +// +// //when +// String actual = acustomer.deposit(5000); +// +// //then +// Assert.assertEquals(expected,actual); +// +// +// } + + + + + + + diff --git a/src/main/test/CustomerWarehouseTest.java b/src/main/test/CustomerWarehouseTest.java new file mode 100644 index 0000000..4cbd563 --- /dev/null +++ b/src/main/test/CustomerWarehouseTest.java @@ -0,0 +1,48 @@ +import org.junit.Assert; +import org.junit.Test; + +public class CustomerWarehouseTest { + + @Test + public void lookupCustomerTest(){ + //given + Customer expected = new Customer(); + CustomerWarehouse.addCustomer(expected); + + //when + Customer actual = CustomerWarehouse.lookupCustomer(expected.getUsername()); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void addCustomer(){ + //given +// CustomerWarehouse customers = new CustomerWarehouse(); + Customer expected = new Customer(); + CustomerWarehouse.addCustomer(expected); + + //when + Customer actual = CustomerWarehouse.lookupCustomer(expected.getUsername()); + + //then + Assert.assertEquals(expected,actual); + + } + + @Test + public void removeCustomerTest(){ + //given + Customer expected = null; + Customer customer = new Customer(); + CustomerWarehouse.addCustomer(customer); + + //when + CustomerWarehouse.removeCustomer(customer); + Customer actual = CustomerWarehouse.lookupCustomer(customer.getUsername()); + + //then + Assert.assertEquals(expected,actual); + } +}