diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4db2a73 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.idea +target diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..55e21b6 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_12.xml b/.idea/libraries/Maven__junit_junit_4_12.xml new file mode 100644 index 0000000..d411041 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Access Control UML.png b/Access Control UML.png new file mode 100644 index 0000000..d0b04b8 Binary files /dev/null and b/Access Control UML.png differ diff --git a/Access_Control_Lab.iml b/Access_Control_Lab.iml new file mode 100644 index 0000000..5cf6df2 --- /dev/null +++ b/Access_Control_Lab.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b5c240d --- /dev/null +++ b/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + battin.preston + AccessControl + 1.0-SNAPSHOT + + + + junit + junit + 4.12 + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.0 + + 1.8 + 1.8 + + + + + + + \ No newline at end of file diff --git a/src/main/java/battin/preston/AccessControl/Account.java b/src/main/java/battin/preston/AccessControl/Account.java new file mode 100644 index 0000000..dea6a4f --- /dev/null +++ b/src/main/java/battin/preston/AccessControl/Account.java @@ -0,0 +1,185 @@ +package battin.preston.AccessControl; + +import java.util.ArrayList; + +/** + * Created by prestonbattin on 1/17/17. + */ +public class Account { + + + private String accountType, holdersName, status, overDraftProtection; + private int checkingAccountNumber, savingAccountNumber; + private static int totalSavingAccount, totalCheckingAccounts; + private double balance, rate; + private ArrayList withdrawals = new ArrayList<>(), deposits = new ArrayList<>(), + interestRates = new ArrayList<>(), transfers = new ArrayList<>(); + private ArrayList statuses = new ArrayList<>(), names = new ArrayList<>(); + + + protected Account() { + } + + protected Account(String type, String name) { + if (type.equals("Checking")) { + this.checkingAccountNumber = totalCheckingAccounts; + this.accountType = type; + totalCheckingAccounts++; + } else if (type.equals("Savings")) { + this.savingAccountNumber = totalSavingAccount; + this.accountType = type; + totalSavingAccount++; + } + + this.holdersName = name; + } + + + protected int getAccountNumber(){ + + return this.savingAccountNumber; + + } + + protected void creditAccount(double credit){ + + this.balance += credit; + deposits.add(credit); + System.out.println("Account successfully credited +" + credit); + } + + protected void debitAccount(double debit){ + + this.balance -= debit; + withdrawals.add(-debit); + System.out.println("Account successfully debited -" + debit); + } + + protected ArrayList getDeposits(){ + + return deposits; + } + + protected ArrayList getWithdrawls(){ + + return withdrawals; + } + + protected void setAccountHoldersName(String name){ + + this.holdersName = name; + this.names.add(name); + } + + protected ArrayList getTransfers(){ + + return transfers; + } + + protected void makeTransfer(Account receiving, double money){ + + if((this.holdersName.equals(receiving.holdersName)) && (this.balance > money)){ + this.balance -= money; + receiving.balance += money; + this.transfers.add(-money); + receiving.transfers.add(money); + } else + System.out.println("Not enough money to transfer."); + } + + protected ArrayList getStatuses(){ + + return statuses; + } + + protected ArrayList getNames(){ + + return names; + } + + protected ArrayList getInterestRates(){ + + return interestRates; + } + + + protected void setInterestRates(double rate){ + + this.rate = rate; + this.interestRates.add(rate); + } + + protected void setStatus(String status) { + + if (status.equals("Open")) { + this.status = status; + } + + else if (status.equals("Closed")) { + this.status = status; + } + + else { + this.status = "OFAC Freeze"; + } + + this.statuses.add(status); + } + + protected String getStatus() { + + return this.status; + } + + protected void setOverDraftProtection(String set) { + + this.overDraftProtection = set; + } + + protected String getOverDraftProtection() { + + return this.overDraftProtection; + } + + protected double getRate() { + + return this.rate; + } + + protected double getBalance() { + + return this.balance; + } + + protected String getHoldersName() { + + return this.holdersName; + } + + protected void setRate() { + + if(this.accountType.equals("Savings")) { + this.rate = .06; + this.interestRates.add(.06); + } + else + this.rate = .05; + this.interestRates.add(.05); + + } + +} + + + + + + + + + + + + + + diff --git a/src/main/java/battin/preston/AccessControl/Checking.java b/src/main/java/battin/preston/AccessControl/Checking.java new file mode 100644 index 0000000..52ff47e --- /dev/null +++ b/src/main/java/battin/preston/AccessControl/Checking.java @@ -0,0 +1,21 @@ +package battin.preston.AccessControl; + +/** + * Created by prestonbattin on 1/17/17. + */ +public class Checking extends Account { + + + public Checking(String type, String name){ + super(type, name); + setRate(); + setStatus("Open"); + setOverDraftProtection("On"); + } + + public int getCheckingAccountNumber() { + + return this.getCheckingAccountNumber(); + } + +} diff --git a/src/main/java/battin/preston/AccessControl/Main.java b/src/main/java/battin/preston/AccessControl/Main.java new file mode 100644 index 0000000..21880cc --- /dev/null +++ b/src/main/java/battin/preston/AccessControl/Main.java @@ -0,0 +1,38 @@ +package battin.preston.AccessControl; + +import java.util.ArrayList; +import java.util.Scanner; + +/** + * Created by prestonbattin on 1/17/17. + */ +public class Main { + + static Scanner input = new Scanner(System.in); + static ArrayList checkingAccount = new ArrayList<>(); + static ArrayList savingsAccount = new ArrayList<>(); + static int i; + + public static void main(String[] args) { + + OpenAccount openedAccount = new OpenAccount(); + openedAccount.getNameandAccountType(); + openedAccount.openAccount(); + + + + + + + + + + + + + + + + + } +} diff --git a/src/main/java/battin/preston/AccessControl/MainMenu.java b/src/main/java/battin/preston/AccessControl/MainMenu.java new file mode 100644 index 0000000..488074c --- /dev/null +++ b/src/main/java/battin/preston/AccessControl/MainMenu.java @@ -0,0 +1,69 @@ +package battin.preston.AccessControl; + +import static battin.preston.AccessControl.Main.*; +import static battin.preston.AccessControl.OpenAccount.choice; + +/** + * Created by prestonbattin on 1/17/17. + */ +public class MainMenu { + + static void decideChecking(){ + + System.out.println("What would you like to do today " + checkingAccount.get(i).getHoldersName() + "?"); + choice = input.nextLine(); + MainMenu.MenuItems(choice); + } + + static void decideSavings(){ + + System.out.println("What would you like to do today " + savingsAccount.get(i).getHoldersName() + "?"); + choice = input.nextLine(); + MainMenu.MenuItems(choice); + } + + static void MenuItems(String pick){ + + switch(pick){ + + case "Transfer": + + + break; + + case "Inquiries": + + break; + + case "Credit": + + break; + + case "Debit": + + break; + + case "Change Name": + + break; + + case "Close": + + break; + + case "Freeze": + + break; + + default: + + System.out.println("Options: Transfer, Inquiries, Credit, Debit, Change Name, Close, Freeze."); + + + + + } + + } + +} diff --git a/src/main/java/battin/preston/AccessControl/OpenAccount.java b/src/main/java/battin/preston/AccessControl/OpenAccount.java new file mode 100644 index 0000000..ae1408f --- /dev/null +++ b/src/main/java/battin/preston/AccessControl/OpenAccount.java @@ -0,0 +1,31 @@ +package battin.preston.AccessControl; + +import static battin.preston.AccessControl.Main.*; + +/** + * Created by prestonbattin on 1/17/17. + */ +public class OpenAccount { + + protected static String choice, name; + + public static void getNameandAccountType() { + + System.out.println("Would you like to open a Checking or Savings account?"); + choice = input.nextLine(); + System.out.println("What is your full name?"); + name = input.nextLine(); + } + + public void openAccount() { + if (choice.equals("Checking")) { + Checking account = new Checking(choice, name); + checkingAccount.add(account); + MainMenu.decideChecking(); + } else if (choice.equals("Savings")) { + Savings account = new Savings(choice, name); + savingsAccount.add(account); + MainMenu.decideSavings(); + } + } +} diff --git a/src/main/java/battin/preston/AccessControl/Savings.java b/src/main/java/battin/preston/AccessControl/Savings.java new file mode 100644 index 0000000..6408189 --- /dev/null +++ b/src/main/java/battin/preston/AccessControl/Savings.java @@ -0,0 +1,28 @@ +package battin.preston.AccessControl; + +/** + * Created by prestonbattin on 1/17/17. + */ +public class Savings extends Account { + + + + + public Savings(String type, String name){ + super(type, name); + setRate(); + setStatus("Open"); + setOverDraftProtection("On"); + } + + + + protected int getSavingAccountNumber() { + + return this.getSavingAccountNumber(); + } + +} + + + diff --git a/src/test/java/battin/preston/AccessControl/AccountTest.java b/src/test/java/battin/preston/AccessControl/AccountTest.java new file mode 100644 index 0000000..166c58c --- /dev/null +++ b/src/test/java/battin/preston/AccessControl/AccountTest.java @@ -0,0 +1,115 @@ +package battin.preston.AccessControl; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by prestonbattin on 1/17/17. + */ +public class AccountTest { + + @Test + public void AccountCreationTest() { + + Checking test = new Checking("Checking", "Sally"); + Checking test2 = new Checking("Checking", "Steve"); + int expected = 1; + int actual = test2.getCheckingAccountNumber(); + Assert.assertEquals(expected, actual); + Assert.assertEquals("Sally", test.getHoldersName()); + + } + + @Test + public void CheckingBalanceTest(){ + Checking test = new Checking("Checking", "SAlly"); + double expected = 0; + double actual = test.getBalance(); + Assert.assertEquals(expected,actual,0); + } + + @Test + public void TestCreditAccount(){ + Checking test = new Checking("Checking", "Sally"); + test.creditAccount(100.0); + double expected = 100; + double actual = test.getBalance(); + Assert.assertEquals(expected, actual,0); + Assert.assertEquals(expected, test.getDeposits().get(0),0); + } + + @Test + public void TestDebitAccount() { + Checking test = new Checking("Checking", "Foo"); + test.debitAccount(100); + double expected = -100; + double actual = test.getBalance(); + Assert.assertEquals(expected, actual, 0); + Assert.assertEquals(expected, test.getWithdrawls().get(0), 0); + } + + @Test + public void TestSetAccountHoldersName(){ + Checking test = new Checking("Checking", "Foo"); + test.setAccountHoldersName("Bar"); + String expected = "Bar"; + String actual = test.getHoldersName(); + Assert.assertEquals(expected, actual); + } + + @Test + public void TestTansfers(){ + Checking test = new Checking("Checking", "Foo"); + Savings testFoo = new Savings("Savings", "Foo"); + test.creditAccount(5000); + test.makeTransfer(testFoo, 600); + double expected = 600; + double actual = testFoo.getBalance(); + Assert.assertEquals(expected,actual,0); + System.out.println(test.getTransfers()); + System.out.println(testFoo.getTransfers()); + } + + + @Test + public void TestInterestRates(){ + Checking test = new Checking("Checking", "Foo"); + double expected = .05; + double actual = test.getRate(); + Assert.assertEquals(expected,actual,0); + test.setInterestRates(100); + Assert.assertEquals(100, test.getRate(),0); + + } + + @Test + public void TestSetName(){ + Checking test = new Checking("Checking", "Foo"); + test.setAccountHoldersName("Kevin"); + String expected = "Kevin"; + String actual = test.getHoldersName(); + Assert.assertEquals(expected,actual); + + } + + + @Test + public void TestSetStatus(){ + Checking test = new Checking("Checking", "Foo"); + String expected = "Open"; + String actual = test.getStatus(); + Assert.assertEquals(expected,actual); + Assert.assertEquals(expected, test.getStatuses().get(0)); + } + + + @Test + public void TestOverDraftProtection(){ + Checking test = new Checking("Checking", "Foo"); + String expected = "On"; + String actaul = test.getOverDraftProtection(); + Assert.assertEquals(expected, actaul ); + } + + } +