diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..a0ebd10 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +AccessControlLabs \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..6a906ca --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dictionaries/randallcrame.xml b/.idea/dictionaries/randallcrame.xml new file mode 100644 index 0000000..970cf57 --- /dev/null +++ b/.idea/dictionaries/randallcrame.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..8d66637 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,5 @@ + + + + \ 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/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..49b6227 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,95 @@ + + + + false + + false + false + + + + + + + + + + + + + + + Android + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..767d9ff --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..0c0755e --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,1088 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1484681836300 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AccessControlLabUML b/AccessControlLabUML new file mode 100644 index 0000000..0e50e92 Binary files /dev/null and b/AccessControlLabUML differ diff --git a/AccessControlLabUML.xml b/AccessControlLabUML.xml new file mode 100644 index 0000000..e5f8bfc --- /dev/null +++ b/AccessControlLabUML.xml @@ -0,0 +1 @@ +7VrRbuI4FP0apM5DVw0pFB4hLW213VIVZlbaN5MYYtWxGduUtl+/14kNCXGZEKA7KzGqRvGNfX3tc+5xbNzwg+TtVqB5/BePMG00L6K3hn/daDZbnS78rw3vmeGy3ckMM0GizOStDSPygY3xwlgXJMKyUFFxThWZF40hZwyHqmBDQvBlsdqU02KvczTDJcMoRLRs/ZtEKs6sndbF2n6HySy2PXsX5s0EhS8zwRfM9Ndo+tP0X/Y6QdaXqS9jFPFlzuTfNPxAcK6yp+QtwFRPrZ22rN3gk7eruAVmqkqDZtbgFdGFGXofsZdeGMIQlAlRvdtpkUuSUMSg1I9VQsHoweOUMzUylXQZUTJj8BxCDFiA4RULRWBye+aF4nOwhjGh0QN65wsdqVQwc7bUj7kgH+AW2T7gtVCGJ812ocZItwTzBVgFllDnyQ7fW5kekFSmTsgpRXNJJquAEyRmhPW5UjwxlexIB4TSgFMu0gmwWPp9M20wMPz26dR7K0AhTzBPsBLvUMU08C2bbI6Y4nJNON/a4hzZutaIDMlnK9droOHBYO3G3S/hfq49ZriP3+dg7IEhJUJalo1mm2poIvIKjzP9eG7qPy6SiQZat6CczWxVCCJXe4sDoAxioekz4gsNza4+7iDHsZCPKDF+RkqQGrHca9JiqZ6R2i8g4KVayMwFZoukugMOvLoWaFrZxUaaAidVMUWlEvwFWyIznqbwNMdtY7KpS/FUfZq4co5CmNmHtM715drybEiqTcuYKDwCu45pCYsE2PS4pjSVu5hEEWY6PTmMEWW5qBNvzglTKbFbffgDqgcXf7Q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_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..c1e5521 --- /dev/null +++ b/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + crame.randall + AccessControlLabs + 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/crame/randall/AccessControlLab/AccountNumberGenerator.java b/src/main/java/crame/randall/AccessControlLab/AccountNumberGenerator.java new file mode 100644 index 0000000..d80e35a --- /dev/null +++ b/src/main/java/crame/randall/AccessControlLab/AccountNumberGenerator.java @@ -0,0 +1,16 @@ +package crame.randall.AccessControlLab; + +/** + * Created by randallcrame on 1/17/17. + */ +class AccountNumberGenerator { + static long accountNumberGenerated = 360000000; + + static long createAccountNumber(){ + return accountNumberGenerated+=2; + + } + + + +} diff --git a/src/main/java/crame/randall/AccessControlLab/AccountStatus.java b/src/main/java/crame/randall/AccessControlLab/AccountStatus.java new file mode 100644 index 0000000..2ed1922 --- /dev/null +++ b/src/main/java/crame/randall/AccessControlLab/AccountStatus.java @@ -0,0 +1,9 @@ +package crame.randall.AccessControlLab; + +/** + * Created by randallcrame on 1/17/17. + */ +public enum AccountStatus { + OPEN, CLOSED, FROZEN + +} diff --git a/src/main/java/crame/randall/AccessControlLab/AccountTypes.java b/src/main/java/crame/randall/AccessControlLab/AccountTypes.java new file mode 100644 index 0000000..097113b --- /dev/null +++ b/src/main/java/crame/randall/AccessControlLab/AccountTypes.java @@ -0,0 +1,8 @@ +package crame.randall.AccessControlLab; + +/** + * Created by randallcrame on 1/17/17. + */ +public enum AccountTypes { + SAVINGS, CHECKING, INVESTING +} diff --git a/src/main/java/crame/randall/AccessControlLab/BankAccount.java b/src/main/java/crame/randall/AccessControlLab/BankAccount.java new file mode 100644 index 0000000..281bffc --- /dev/null +++ b/src/main/java/crame/randall/AccessControlLab/BankAccount.java @@ -0,0 +1,172 @@ +package crame.randall.AccessControlLab; + +/** + * Created by randallcrame on 1/17/17. + */ +public class BankAccount { + private AccountTypes accountType; + final long accountNumber = AccountNumberGenerator.createAccountNumber(); + + double accountBalance = 100.00; + + String accountHoldersName = "Enter Name"; + double accountInterestRate = 0.00; + AccountStatus accountStatus = AccountStatus.OPEN; + OverDraftStatus overDraftStatus = OverDraftStatus.OFF; + private String bankLog= ""; + private BankAccount() {} + + public BankAccount(AccountTypes accountTypes,String accountHoldersName) { + setAccountType(accountTypes); + setAccountHoldersName(accountHoldersName); + } + + public String getBankLog() { + return bankLog; + } + void setAccountType(AccountTypes input){ + this.accountType = input; + } + + public AccountTypes getAccountType() { + return this.accountType; + } + + public long getAccountNumber() { + return this.accountNumber; + } + + void setAccountBalance(double input){ + if (isAccountOpen(getAccountStatus())) { + this.accountBalance = input; + bankLog += "change balance" + getAccountBalance()+", \n"; + } + + } + + public double getAccountBalance(){ + return this.accountBalance; + } + + public void setAccountHoldersName(String input) { + if (isAccountOpen(getAccountStatus())) { + this.accountHoldersName = input; + bankLog += "change name " + getAccountHoldersName()+", \n"; + } + } + + public String getAccountHoldersName() { + return this.accountHoldersName; + } + + void setAccountInterestRate(double input){ + this.accountInterestRate = input; + bankLog += "change Interest Rate " + getAccountInterestRate()+", \n"; + } + public double getAccountInterestRate() { + return this.accountInterestRate; + } + void setAccountStatus(AccountStatus input) { + if (isAccountOpen(getAccountStatus()) || isAccountFrozen(getAccountStatus())) + this.accountStatus = input; + bankLog += "change Account Status " + getAccountStatus()+", \n"; + } + void setAccountToClose(){ + if (getAccountBalance() == 0.00) { + setAccountStatus(AccountStatus.CLOSED); + } + } + + public AccountStatus getAccountStatus() { + return accountStatus; + } + + public void setOverDraftStatus(OverDraftStatus input){ + this.overDraftStatus = input; + bankLog += "change Overdraft " + getOverDraftStatus()+", \n"; + } + + public OverDraftStatus getOverDraftStatus(){ + return overDraftStatus; + } + private boolean isAccountOpen(AccountStatus input) { + return input.equals(AccountStatus.OPEN); + } + + + private boolean isAccountFrozen(AccountStatus input) { + return input.equals(AccountStatus.FROZEN); + } + private boolean isOverDraftEnabled(OverDraftStatus input){ + return input.equals((OverDraftStatus.ON)); + } + + private boolean isNSF(double amount){ + return (amount <= getAccountBalance() || isOverDraftEnabled(getOverDraftStatus())); + } + + private String unableToCompleteRequest(){ + return "Unable to Complete Request..."; + } + public String balanceInquiry(){ + return (isAccountFrozen(getAccountStatus())) ? unableToCompleteRequest(): String.valueOf(getAccountBalance()); + } + + private String debitAccount(double input){ + this.accountBalance-= input; + bankLog += "change balance " + getAccountBalance() +", \n"; + return "Debit Complete"; + } + + public String requestDebitAccount(double input){ + return (isAccountOpen(getAccountStatus()) && isNSF(input)) ? debitAccount(input) : unableToCompleteRequest(); + } + + private String creditAccount(double input){ + this.accountBalance+= input; + bankLog += "change Balance " + getAccountBalance()+", \n"; + return "Credit Complete"; + } + + public String requestCreditAccount(double input) { + return (isAccountOpen(getAccountStatus()))? creditAccount(input) : unableToCompleteRequest(); + } + private boolean accountOwnershipCheck(BankAccount input){ + return (getAccountHoldersName().equals(input.getAccountHoldersName())); + } + + private boolean areFundsTransferable(BankAccount account){ + return (accountOwnershipCheck(account) + && isAccountOpen(this.getAccountStatus()) + && isAccountOpen(account.getAccountStatus())); + } + + private String debitTransfer(BankAccount account, double amount){ + this.setAccountBalance(this.accountBalance-= amount); + account.setAccountBalance(account.accountBalance+=amount); + bankLog += "change balance " + getAccountNumber() + ": " + getAccountBalance() + + " " + account.getAccountNumber() + ": " + account.getAccountBalance() + ", \n"; + return "Transfer Complete"; + } + + private String creditTransfer(BankAccount account, double amount){ + account.setAccountBalance(account.accountBalance-=amount); + this.setAccountBalance(this.accountBalance+=amount); + bankLog += "change balance " + getAccountNumber() + ": " + getAccountBalance() + + " " + account.getAccountNumber() + ": " + account.getAccountBalance() + ", \n"; + return "Transfer Complete"; + } + + public String requestTransferToAccount(BankAccount account, double amount) { + return areFundsTransferable(account) && this.isNSF(amount) + ? debitTransfer(account, amount): unableToCompleteRequest(); + } + + public String requestTransferFromAccount(BankAccount account, double amount) { + return areFundsTransferable(account) && account.isNSF(amount) + ? creditTransfer(account, amount): unableToCompleteRequest(); + } + +} + + diff --git a/src/main/java/crame/randall/AccessControlLab/OverDraftStatus.java b/src/main/java/crame/randall/AccessControlLab/OverDraftStatus.java new file mode 100644 index 0000000..2dab7d1 --- /dev/null +++ b/src/main/java/crame/randall/AccessControlLab/OverDraftStatus.java @@ -0,0 +1,8 @@ +package crame.randall.AccessControlLab; + +/** + * Created by randallcrame on 1/17/17. + */ +enum OverDraftStatus { + ON, OFF, AUTO +} diff --git a/src/test/java/crame/randall/AccessControlLabTest/BankAccountTest.java b/src/test/java/crame/randall/AccessControlLabTest/BankAccountTest.java new file mode 100644 index 0000000..138fa9a --- /dev/null +++ b/src/test/java/crame/randall/AccessControlLabTest/BankAccountTest.java @@ -0,0 +1,101 @@ +package crame.randall.AccessControlLabTest; + +import crame.randall.AccessControlLab.AccountStatus; +import crame.randall.AccessControlLab.AccountTypes; +import crame.randall.AccessControlLab.BankAccount; +import org.junit.*; + +/** + * Created by randallcrame on 1/17/17. + */ +public class BankAccountTest { + BankAccount testAccount = new BankAccount(AccountTypes.CHECKING, "Randall"); + BankAccount secondTestAccount = new BankAccount(AccountTypes.CHECKING, "Randall"); + + @Test + public void getAccountTypesTest(){ + AccountTypes expected = AccountTypes.CHECKING; + AccountTypes actual = testAccount.getAccountType(); + Assert.assertEquals(expected, actual); + } + + @Test + public void createAccountNumberTest(){ + long expected = 360000004; + long actual = secondTestAccount.getAccountNumber(); + Assert.assertEquals(expected,actual); + } + + @Test + public void getAccountBalanceTest(){ + double expected = 0.0; + double actual = testAccount.getAccountBalance(); + Assert.assertEquals(expected,actual, 0.0); + } + + @Test + public void getAccountHolderNameTest(){ + String expected = "Enter Name"; + String actual = testAccount.getAccountHoldersName(); + Assert.assertEquals(expected, actual); + } + + @Test + public void getAccountInterestRateTest(){ + double expected = 0.0; + double actual = testAccount.getAccountInterestRate(); + Assert.assertEquals(expected, actual, 0.0); + } + + @Test + public void getAccountStatusTest(){ + AccountStatus expected = AccountStatus.OPEN; + AccountStatus actual = testAccount.getAccountStatus(); + Assert.assertEquals(expected, actual); + } + + @Test + public void balanceInquiryTest(){ + String expected = "0.0"; + String actual = testAccount.balanceInquiry(); + Assert.assertEquals(expected, actual); + } + + @Test + public void requestDebitAccount(){ + String expected = "Unable to Complete Request..."; + String actual = testAccount.requestDebitAccount(10000); + Assert.assertEquals(expected, actual); + } + + @Test + public void requestCreditAccount(){ + String expected = "Credit Complete"; + String actual = testAccount.requestCreditAccount(20); + Assert.assertEquals(expected, actual); + } + + @Test + public void requestTransferToAccountTest(){ + String expected = "Transfer Complete"; + String actual = testAccount.requestTransferToAccount(secondTestAccount, 25); + System.out.println(testAccount.getAccountBalance()); + Assert.assertEquals(expected, actual); + } + + @Test + public void requestTransferFromAccountTest(){ + String expected = "Transfer Complete"; + String actual = testAccount.requestTransferFromAccount(secondTestAccount, 25); + System.out.println(testAccount.getAccountBalance()); + System.out.println(testAccount.getBankLog()); + Assert.assertEquals(expected, actual); + } + + @Test + public void setAccountNameTest(){ + String expected = "Randall"; + String actual = testAccount.getAccountHoldersName(); + Assert.assertEquals(expected,actual); + } +} diff --git a/target/classes/crame/randall/AccessControlLab/AccountNumberGenerator.class b/target/classes/crame/randall/AccessControlLab/AccountNumberGenerator.class new file mode 100644 index 0000000..727f989 Binary files /dev/null and b/target/classes/crame/randall/AccessControlLab/AccountNumberGenerator.class differ diff --git a/target/classes/crame/randall/AccessControlLab/AccountStatus.class b/target/classes/crame/randall/AccessControlLab/AccountStatus.class new file mode 100644 index 0000000..fdcf85e Binary files /dev/null and b/target/classes/crame/randall/AccessControlLab/AccountStatus.class differ diff --git a/target/classes/crame/randall/AccessControlLab/AccountTypes.class b/target/classes/crame/randall/AccessControlLab/AccountTypes.class new file mode 100644 index 0000000..eb9af02 Binary files /dev/null and b/target/classes/crame/randall/AccessControlLab/AccountTypes.class differ diff --git a/target/classes/crame/randall/AccessControlLab/BankAccount.class b/target/classes/crame/randall/AccessControlLab/BankAccount.class new file mode 100644 index 0000000..eb399e0 Binary files /dev/null and b/target/classes/crame/randall/AccessControlLab/BankAccount.class differ diff --git a/target/classes/crame/randall/AccessControlLab/OverDraftStatus.class b/target/classes/crame/randall/AccessControlLab/OverDraftStatus.class new file mode 100644 index 0000000..e6df339 Binary files /dev/null and b/target/classes/crame/randall/AccessControlLab/OverDraftStatus.class differ diff --git a/target/test-classes/crame/randall/AccessControlLabTest/BankAccountTest.class b/target/test-classes/crame/randall/AccessControlLabTest/BankAccountTest.class new file mode 100644 index 0000000..16472b7 Binary files /dev/null and b/target/test-classes/crame/randall/AccessControlLabTest/BankAccountTest.class differ