diff --git a/BankAccount/BankAccount.html b/BankAccount/BankAccount.html new file mode 100644 index 0000000..539b860 --- /dev/null +++ b/BankAccount/BankAccount.html @@ -0,0 +1,12 @@ + + + + +BankAccount + + + +
+ + + diff --git a/BankAccount/BankAccount.iml b/BankAccount/BankAccount.iml new file mode 100644 index 0000000..03320bd --- /dev/null +++ b/BankAccount/BankAccount.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BankAccount/pom.xml b/BankAccount/pom.xml new file mode 100644 index 0000000..d3e3c02 --- /dev/null +++ b/BankAccount/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + armstrong.alexandra + BankAccount + 1.0-SNAPSHOT + + + + junit + junit + 4.12 + + + + + \ No newline at end of file diff --git a/BankAccount/src/main/java/armstrong/alexandra/AccountType.java b/BankAccount/src/main/java/armstrong/alexandra/AccountType.java new file mode 100644 index 0000000..a3a1fb9 --- /dev/null +++ b/BankAccount/src/main/java/armstrong/alexandra/AccountType.java @@ -0,0 +1,6 @@ +package armstrong.alexandra; + +/** + * Created by alexandraarmstrong on 1/17/17. + */ +public enum AccountType {CHECKING, SAVINGS, INVESTMENT, IRA, MONEY_MARKET} diff --git a/BankAccount/src/main/java/armstrong/alexandra/BankAccount.java b/BankAccount/src/main/java/armstrong/alexandra/BankAccount.java new file mode 100644 index 0000000..6bb1b1f --- /dev/null +++ b/BankAccount/src/main/java/armstrong/alexandra/BankAccount.java @@ -0,0 +1,194 @@ +package armstrong.alexandra; + +import java.io.*; + +import static armstrong.alexandra.Status.*; +import static armstrong.alexandra.AccountType.*; +import static armstrong.alexandra.Overdraft.*; + +/** + * Created by alexandraarmstrong on 1/17/17. + */ +public class BankAccount { + private final static int ROUTERNUMBER = 1234567; + private static int accountCounter = 0; + + private AccountType accountType; + private long accountNumber; + private double balance = 0; + private String accountHolderName; + private double interestRate = 1.00d; + private Status status = CLOSED; + private Overdraft overdraft = DISABLED; + //private File record; + + BankAccount(AccountType accountType, String accountHolderName){ + this.accountType = accountType; + this.accountHolderName = accountHolderName; + accountCounter++; + accountNumber = Integer.valueOf(String.valueOf(ROUTERNUMBER) + String.valueOf(accountCounter)); + status = OPEN; + } + + BankAccount(AccountType accountType, String accountHolderName, Overdraft overdraft){ + this(accountType, accountHolderName); + this.overdraft = overdraft; + } + + BankAccount(AccountType accountType, String accountHolderName, double interestRate){ + this(accountType, accountHolderName); + this.interestRate = interestRate; + } + + BankAccount(AccountType accountType, String accountHolderName, double interestRate, Overdraft overdraft){ + this(accountType, accountHolderName, overdraft); + this.interestRate = interestRate; + } + + + public AccountType getAccountType(){ + return accountType; + } + + public long getAccountNumber(){ + return accountNumber; + } + + public Double getBalance(){ + if (status == FROZEN) { + return null; + } else { + return balance; + } + } + + public String getAccountHolderName(){ + return accountHolderName; + } + + public double getInterestRate(){ + return interestRate; + } + + public Status getStatus(){ + return status; + } + + public Overdraft getOverdraft() { + return overdraft; + } + + public void setOverdraft(Overdraft overdraft){ + this.overdraft = overdraft; + } + + public void setInterestRate(double interestRate){ + this.interestRate = interestRate; + writeToFileChangeInterestRate(); + } + + protected void setStatus(Status status){ + this.status = status; + writeToFileChangeStatus(); + } + + public String changeBalance(double amount) { + if (status == OPEN) { + if (overdraft == ENABLED) { + if (amount > 0 || amount > getBalance()) { + balance += amount; + writeToFileChangeBalance(); + return "Balance adjusted"; + } else { + return "Insufficient Funds"; + } + } else { + balance += amount; + writeToFileChangeBalance(); + return "Balance adjusted"; + } + } else { + return "Balance inaccessible"; + } + } + + public String transferMoneyToOtherAccount(BankAccount otherAccount, double amount) { + if (accountHolderName.equalsIgnoreCase(otherAccount.accountHolderName)) { + if (getBalance() > amount || overdraft != DISABLED) { + changeBalance(-1 * amount); + otherAccount.changeBalance(amount); + return "Transfer Successful"; + } else { + return "Insufficient funds"; + } + } else { + return "Permission Denied"; + } + } + + public void setAccountHolderName(String name){ + if(status != CLOSED){ + this.accountHolderName = name; + writeToFileChangeName(); + } + } + + public String closeAccount(){ + if(getBalance() == 0d){ + setStatus(CLOSED); + return "Account Closed"; + } else { + return "Please withdraw funds"; + } + } + + public String changeFreezeStatus(){ + if (status == FROZEN) { + setStatus(OPEN); + return "Account unfrozen"; + } else { + setStatus(FROZEN); + return "Account frozen"; + } + } + + private void writeToFileChangeBalance() { + try { + PrintStream print = new PrintStream(new BufferedOutputStream(new FileOutputStream("BankAccount.txt", true))); + print.println("Balance Changed to " + balance + "."); + print.close(); + } catch (IOException e) { + } + } + + private void writeToFileChangeStatus(){ + try { + PrintStream print = new PrintStream(new BufferedOutputStream(new FileOutputStream("BankAccount.txt", true))); + print.println("Status changed to " + status + "."); + print.close(); + } catch (IOException e) { + } + } + + private void writeToFileChangeName(){ + try { + PrintStream print = new PrintStream(new BufferedOutputStream(new FileOutputStream("BankAccount.txt", true))); + print.println("Name changed to " + accountHolderName + "."); + print.close(); + } catch (IOException e) { + } + } + + private void writeToFileChangeInterestRate(){ + try { + PrintStream print = new PrintStream(new BufferedOutputStream(new FileOutputStream("BankAccount.txt", true))); + print.println("Interest rate changed to " + interestRate + "."); + print.close(); + } catch (IOException e) { + } + } + +} + + + diff --git a/BankAccount/src/main/java/armstrong/alexandra/Overdraft.java b/BankAccount/src/main/java/armstrong/alexandra/Overdraft.java new file mode 100644 index 0000000..101b696 --- /dev/null +++ b/BankAccount/src/main/java/armstrong/alexandra/Overdraft.java @@ -0,0 +1,6 @@ +package armstrong.alexandra; + +/** + * Created by alexandraarmstrong on 1/17/17. + */ +public enum Overdraft {ENABLED, DISABLED, AUTOMATIC} diff --git a/BankAccount/src/main/java/armstrong/alexandra/Status.java b/BankAccount/src/main/java/armstrong/alexandra/Status.java new file mode 100644 index 0000000..82a6e06 --- /dev/null +++ b/BankAccount/src/main/java/armstrong/alexandra/Status.java @@ -0,0 +1,6 @@ +package armstrong.alexandra; + +/** + * Created by alexandraarmstrong on 1/17/17. + */ +public enum Status {OPEN, CLOSED, FROZEN} diff --git a/BankAccount/src/test/java/armstrong/alexandra/BankAccountTest.java b/BankAccount/src/test/java/armstrong/alexandra/BankAccountTest.java new file mode 100644 index 0000000..fc1895b --- /dev/null +++ b/BankAccount/src/test/java/armstrong/alexandra/BankAccountTest.java @@ -0,0 +1,237 @@ +package armstrong.alexandra; + +import org.junit.*; + +import static armstrong.alexandra.Status.*; +import static armstrong.alexandra.AccountType.*; +import static armstrong.alexandra.Overdraft.*; +import static junit.framework.TestCase.assertEquals; + +/** + * Created by alexandraarmstrong on 1/17/17. + */ +public class BankAccountTest { + BankAccount ba; + BankAccount bb; + + @Before + public void setUp() { + } + + @Test + public void constructorTest1() { + ba = new BankAccount(SAVINGS, "Alex Armstrong"); + AccountType expected = SAVINGS; + AccountType actual = ba.getAccountType(); + assertEquals(expected, actual); + } + + @Test + public void constructorTest2() { + ba = new BankAccount(SAVINGS, "Alex Armstrong"); + String expected = "Alex Armstrong"; + String actual = ba.getAccountHolderName(); + assertEquals(expected, actual); + } + + @Test + public void constructorTest3() { + ba = new BankAccount(SAVINGS, "Alex Armstrong", ENABLED); + AccountType expected = SAVINGS; + AccountType actual = ba.getAccountType(); + assertEquals(expected, actual); + } + + @Test + public void constructorTest4() { + ba = new BankAccount(SAVINGS, "Alex Armstrong", ENABLED); + String expected = "Alex Armstrong"; + String actual = ba.getAccountHolderName(); + assertEquals(expected, actual); + } + + @Test + public void constructorTest5() { + ba = new BankAccount(SAVINGS, "Alex Armstrong", ENABLED); + Overdraft expected = ENABLED; + Overdraft actual = ba.getOverdraft(); + assertEquals(expected, actual); + } + + @Test + public void constructorTest6() { + ba = new BankAccount(SAVINGS, "Alex Armstrong", 1.04d); + double expected = 1.04d; + double actual = ba.getInterestRate(); + assertEquals(expected, actual); + } + + @Test + public void constructorTest7() { + ba = new BankAccount(SAVINGS, "Alex Armstrong", 1.04d); + AccountType expected = SAVINGS; + AccountType actual = ba.getAccountType(); + assertEquals(expected, actual); + } + + @Test + public void constructorTest8() { + ba = new BankAccount(SAVINGS, "Alex Armstrong", 1.04); + String expected = "Alex Armstrong"; + String actual = ba.getAccountHolderName(); + assertEquals(expected, actual); + } + + @Test + public void constructorTest9() { + ba = new BankAccount(SAVINGS, "Alex Armstrong", 1.04d, ENABLED); + String expected = "Alex Armstrong"; + String actual = ba.getAccountHolderName(); + assertEquals(expected, actual); + } + + @Test + public void constructorTest10() { + ba = new BankAccount(SAVINGS, "Alex Armstrong", 1.04d, ENABLED); + AccountType expected = SAVINGS; + AccountType actual = ba.getAccountType(); + assertEquals(expected, actual); + } + + @Test + public void constructorTest11() { + ba = new BankAccount(SAVINGS, "Alex Armstrong", 1.04d, ENABLED); + Overdraft expected = ENABLED; + Overdraft actual = ba.getOverdraft(); + assertEquals(expected, actual); + } + + @Test + public void constructorTest12() { + ba = new BankAccount(SAVINGS, "Alex Armstrong", 1.04d, ENABLED); + double expected = 1.04d; + double actual = ba.getInterestRate(); + assertEquals(expected, actual); + } + + @Test + public void getBalanceTest(){ + ba = new BankAccount(SAVINGS, "Alex Armstrong"); + ba.setStatus(FROZEN); + Double expected = null; + Double actual = ba.getBalance(); + assertEquals(expected, actual); + } + + @Test + public void changeBalanceTest(){ + ba = new BankAccount(SAVINGS, "Alex Armstrong"); + ba.changeBalance(528d); + ba.changeBalance(-432d); + double expected = 0d + 528d + -432d; + double actual = ba.getBalance(); + assertEquals(expected, actual); + } + + @Test + public void changeBalanceTest2(){ + ba = new BankAccount(SAVINGS, "Alex Armstrong"); + ba.setStatus(CLOSED); + String expected = "Balance inaccessible"; + String actual = ba.changeBalance(-432d); + assertEquals(expected, actual); + } + + @Test + public void TransferFromTest1(){ + ba = new BankAccount(SAVINGS, "Alex Armstrong"); + bb = new BankAccount(SAVINGS, "Alexandra Armstrong"); + String expected = "Permission Denied"; + String actual = ba.transferMoneyToOtherAccount(bb, 40d); + assertEquals(expected, actual); + } + + @Test + public void TransferFromTest2(){ + ba = new BankAccount(SAVINGS, "Alex Armstrong"); + bb = new BankAccount(SAVINGS, "Alex Armstrong"); + ba.changeBalance(30d); + String expected = "Insufficient funds"; + String actual = ba.transferMoneyToOtherAccount(bb, 40d); + assertEquals(expected, actual); + } + + @Test + public void TransferFromTest3(){ + ba = new BankAccount(SAVINGS, "Alex Armstrong"); + bb = new BankAccount(SAVINGS, "Alex Armstrong"); + ba.changeBalance(50d); + String expected = "Transfer Successful"; + String actual = ba.transferMoneyToOtherAccount(bb, 40d); + assertEquals(expected, actual); + } + + @Test + public void setAccountHolderNameTest(){ + ba = new BankAccount(SAVINGS, "Alex Armstrong"); + ba.setAccountHolderName("Alexandra Armstrong"); + String expected = "Alexandra Armstrong"; + String actual = ba.getAccountHolderName(); + assertEquals(expected, actual); + } + + @Test + public void setAccountHolderNameTest2(){ + ba = new BankAccount(SAVINGS, "Alex Armstrong"); + ba.setStatus(CLOSED); + ba.setAccountHolderName("Alexandra Armstrong"); + String expected = "Alex Armstrong"; + String actual = ba.getAccountHolderName(); + assertEquals(expected, actual); + } + + @Test + public void closeAccountTest(){ + ba = new BankAccount(SAVINGS, "Alex Armstrong"); + ba.changeBalance(40d); + String expected = "Please withdraw funds"; + String actual = ba.closeAccount(); + assertEquals(expected, actual); + } + + @Test + public void closeAccountTest2(){ + ba = new BankAccount(SAVINGS, "Alex Armstrong"); + String expected = "Account Closed"; + String actual = ba.closeAccount(); + assertEquals(expected, actual); + } + + @Test + public void changeFreezeStatus(){ + ba = new BankAccount(SAVINGS, "Alex Armstrong"); + String expected = "Account frozen"; + String actual = ba.changeFreezeStatus(); + assertEquals(expected, actual); + } + + @Test + public void changeFreezeStatus2(){ + ba = new BankAccount(SAVINGS, "Alex Armstrong"); + ba.setStatus(FROZEN); + String expected = "Account unfrozen"; + String actual = ba.changeFreezeStatus(); + assertEquals(expected, actual); + } + + @Test + public void writeToFileTest(){ + ba = new BankAccount(SAVINGS, "Alex Armstrong"); + ba.changeBalance(40); + ba.changeBalance( -20); + ba.setStatus(CLOSED); + ba.setStatus(OPEN); + ba.setAccountHolderName("Alexandra Armstrong"); + ba.setInterestRate(1.04d); + } +} \ No newline at end of file diff --git a/BankAccount/target/classes/armstrong/alexandra/AccountType.class b/BankAccount/target/classes/armstrong/alexandra/AccountType.class new file mode 100644 index 0000000..d18eda8 Binary files /dev/null and b/BankAccount/target/classes/armstrong/alexandra/AccountType.class differ diff --git a/BankAccount/target/classes/armstrong/alexandra/BankAccount.class b/BankAccount/target/classes/armstrong/alexandra/BankAccount.class new file mode 100644 index 0000000..44ecbd7 Binary files /dev/null and b/BankAccount/target/classes/armstrong/alexandra/BankAccount.class differ diff --git a/BankAccount/target/classes/armstrong/alexandra/Overdraft.class b/BankAccount/target/classes/armstrong/alexandra/Overdraft.class new file mode 100644 index 0000000..bf32389 Binary files /dev/null and b/BankAccount/target/classes/armstrong/alexandra/Overdraft.class differ diff --git a/BankAccount/target/classes/armstrong/alexandra/Status.class b/BankAccount/target/classes/armstrong/alexandra/Status.class new file mode 100644 index 0000000..9289979 Binary files /dev/null and b/BankAccount/target/classes/armstrong/alexandra/Status.class differ diff --git a/BankAccount/target/test-classes/armstrong/alexandra/BankAccountTest.class b/BankAccount/target/test-classes/armstrong/alexandra/BankAccountTest.class new file mode 100644 index 0000000..2838866 Binary files /dev/null and b/BankAccount/target/test-classes/armstrong/alexandra/BankAccountTest.class differ