diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..c2ba6ab --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +BankAccount \ 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/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..590a53b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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..601028e --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,1102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1484684547653 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + file://$PROJECT_DIR$/src/test/java/holland/andres/CloseAccountTest.java + 8 + + + + file://$PROJECT_DIR$/src/test/java/holland/andres/CloseAccountTest.java + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.8 + + + + + + + + Access_Control_Lab + + + + + + + + Maven: junit:junit:4.12 + + + + + + + + \ No newline at end of file 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/UML.jpg b/UML.jpg new file mode 100644 index 0000000..ce1c40d Binary files /dev/null and b/UML.jpg differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..88bf5d0 --- /dev/null +++ b/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + holland.andres + BankAccount + 1.0-SNAPSHOT + + + junit + junit + RELEASE + + + + + junit + junit + 4.12 + test + + + + \ No newline at end of file diff --git a/src/main/java/holland/andres/Account.java b/src/main/java/holland/andres/Account.java new file mode 100644 index 0000000..d6b8d0c --- /dev/null +++ b/src/main/java/holland/andres/Account.java @@ -0,0 +1,57 @@ +package holland.andres; + +public class Account { + + private String accountName; + private String accountType; + private String overdraftProtection; + private double interest; + private String accountStatus = "open"; + private static int accountNumberCreator = 0; + private int accountNumber; + private double accountBalance = 0; + + public Account (String name, String type, String overdraft, double interestRate) { + this.accountName = name; + this.accountType = type; + this.overdraftProtection = overdraft; + this.interest = interestRate; + accountNumber = accountNumberCreator; + accountNumberCreator++; + } + + public void setAccountName (String name) { + if (accountStatus != "closed") { + accountName = name; + } + } + + public String getAccountStatus () { + return accountStatus; + } + + public void setAccountStatus (String status) { + accountStatus = status; + } + + public double getAccountBalance () { + return accountBalance; + } + + public String getAccountName () { + return accountName; + } + + public void setAccountBalance (double balance) { + accountBalance = balance; + } + + public String getOverdraftProtection () { + return overdraftProtection; + } + + public int getAccountNumber () { + return accountNumber; + } + + } \ No newline at end of file diff --git a/src/main/java/holland/andres/BalanceInquiry.java b/src/main/java/holland/andres/BalanceInquiry.java new file mode 100644 index 0000000..e6d475a --- /dev/null +++ b/src/main/java/holland/andres/BalanceInquiry.java @@ -0,0 +1,12 @@ +package holland.andres; + +public class BalanceInquiry { + public void inquire (Account account) { + String status = account.getAccountStatus(); + if (status.equalsIgnoreCase("open") || + status.equalsIgnoreCase("closed")) { + double balance = account.getAccountBalance(); + System.out.println(balance); + } + } +} diff --git a/src/main/java/holland/andres/ChangeName.java b/src/main/java/holland/andres/ChangeName.java new file mode 100644 index 0000000..f2e8da6 --- /dev/null +++ b/src/main/java/holland/andres/ChangeName.java @@ -0,0 +1,7 @@ +package holland.andres; + +public class ChangeName { + public void change (Account account, String name) { + account.setAccountName(name); + } +} diff --git a/src/main/java/holland/andres/CloseAccount.java b/src/main/java/holland/andres/CloseAccount.java new file mode 100644 index 0000000..26fcda0 --- /dev/null +++ b/src/main/java/holland/andres/CloseAccount.java @@ -0,0 +1,10 @@ +package holland.andres; + +public class CloseAccount { + + public void close (Account account) { + double balance = account.getAccountBalance(); + account.setAccountBalance(balance); + account.setAccountStatus("closed"); + } +} diff --git a/src/main/java/holland/andres/CreditAccount.java b/src/main/java/holland/andres/CreditAccount.java new file mode 100644 index 0000000..60c6449 --- /dev/null +++ b/src/main/java/holland/andres/CreditAccount.java @@ -0,0 +1,14 @@ +package holland.andres; + +public class CreditAccount { + + public boolean credit (Account account, double amount) { + String status = account.getAccountStatus(); + double balance = account.getAccountBalance(); + if (status.equalsIgnoreCase("open")) { + account.setAccountBalance(balance + amount); + return true; + } + return false; + } +} diff --git a/src/main/java/holland/andres/DebitAccount.java b/src/main/java/holland/andres/DebitAccount.java new file mode 100644 index 0000000..4ae93cb --- /dev/null +++ b/src/main/java/holland/andres/DebitAccount.java @@ -0,0 +1,20 @@ +package holland.andres; + +public class DebitAccount { + + public boolean debit (Account account, double amount) { + String status = account.getAccountStatus(); + String overdraft = account.getOverdraftProtection(); + double balance = account.getAccountBalance(); + if (status.equalsIgnoreCase("open") && + overdraft.equalsIgnoreCase("disabled")) { + account.setAccountBalance(balance - amount); + return true; + } + else if (status.equalsIgnoreCase("open") && amount < balance) { + account.setAccountBalance(balance - amount); + return true; + } + return false; + } +} diff --git a/src/main/java/holland/andres/Main.java b/src/main/java/holland/andres/Main.java new file mode 100644 index 0000000..f7b08bc --- /dev/null +++ b/src/main/java/holland/andres/Main.java @@ -0,0 +1,6 @@ +package holland.andres; + +public class Main { + public static void main(String[] args) { + } +} diff --git a/src/test/java/holland/andres/AccountTest.java b/src/test/java/holland/andres/AccountTest.java new file mode 100644 index 0000000..b06a048 --- /dev/null +++ b/src/test/java/holland/andres/AccountTest.java @@ -0,0 +1,38 @@ +package holland.andres; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class AccountTest { + + @Test + public void EachAccountHasUniqueID () { + Account account1 = new Account("Tariq","checking","disabled",0); + Account account2 = new Account("Uncle Phil","savings","enabled",5); + int account1Number = account1.getAccountNumber(); + int account2Number = account2.getAccountNumber(); + boolean actual = (account1Number == account2Number); + assertEquals(false, actual); + } + + @Test + public void ChangeNameIfAccountOpen () { + Account account1 = new Account("Tariq","checking","disabled",0); + account1.setAccountName("Uncle Phil"); + String expected = "Uncle Phil"; + String actual = account1.getAccountName(); + assertEquals(expected, actual); + } + + @Test + public void ChangeNameIfAccountClosed () { + Account account1 = new Account("Tariq","checking","disabled",0); + account1.setAccountStatus("closed"); + account1.setAccountName("Uncle Phil"); + String expected = "Tariq"; + String actual = account1.getAccountName(); + assertEquals(expected, actual); + } + +} \ No newline at end of file diff --git a/src/test/java/holland/andres/ChangeNameTest.java b/src/test/java/holland/andres/ChangeNameTest.java new file mode 100644 index 0000000..78fa245 --- /dev/null +++ b/src/test/java/holland/andres/ChangeNameTest.java @@ -0,0 +1,26 @@ +package holland.andres; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ChangeNameTest { + + @Test + public void ChangeNameFromTariqToProfessorT () { + Account account = new Account("Tariq","checking","disabled",0); + ChangeName changeName = new ChangeName(); + changeName.change(account, "Professor T."); + String expected = "Professor T."; + String actual = account.getAccountName(); + assertEquals(expected, actual); + } + + @Test + public void dontChangeName () { + Account account = new Account("Tariq","checking","disabled",0); + String expected = "Tariq"; + String actual = account.getAccountName(); + assertEquals(expected, actual); + } +} \ No newline at end of file diff --git a/src/test/java/holland/andres/CloseAccountTest.java b/src/test/java/holland/andres/CloseAccountTest.java new file mode 100644 index 0000000..8054d3e --- /dev/null +++ b/src/test/java/holland/andres/CloseAccountTest.java @@ -0,0 +1,25 @@ +package holland.andres; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CloseAccountTest { + @Test + public void CloseAccount () { + Account account = new Account("name","checking","disabled",0); + CloseAccount closeAccount = new CloseAccount(); + closeAccount.close(account); + String expected = "closed"; + String actual = account.getAccountStatus(); + assertEquals(expected, actual); + } + + @Test + public void DefaultAccountStatus() { + Account account = new Account("name","checking","disabled",0); + String expected = "open"; + String actual = account.getAccountStatus(); + assertEquals(expected, actual); + } +} \ No newline at end of file diff --git a/src/test/java/holland/andres/CreditAccountTest.java b/src/test/java/holland/andres/CreditAccountTest.java new file mode 100644 index 0000000..5ebc2ab --- /dev/null +++ b/src/test/java/holland/andres/CreditAccountTest.java @@ -0,0 +1,37 @@ +package holland.andres; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CreditAccountTest { + + @Test + public void CreditOpenAccount () { + Account account1 = new Account("Tariq","checking","disabled",0); + CreditAccount creditAccount = new CreditAccount(); + boolean actual = creditAccount.credit(account1, 10); + assertEquals(true, actual); + } + + @Test + public void CreditClosedAccount () { + Account account1 = new Account("Tariq","checking","disabled",0); + CreditAccount creditAccount = new CreditAccount(); + account1.setAccountStatus("closed"); + boolean actual = creditAccount.credit(account1, 10); + assertEquals(false, actual); + } + + @Test + public void CreditFrozenAccount () { + Account account1 = new Account("Tariq","checking","disabled",0); + CreditAccount creditAccount = new CreditAccount(); + account1.setAccountStatus("frozen"); + boolean actual = creditAccount.credit(account1, 10); + assertEquals(false, actual); + } + + + +} \ No newline at end of file diff --git a/src/test/java/holland/andres/DebitAccountTest.java b/src/test/java/holland/andres/DebitAccountTest.java new file mode 100644 index 0000000..c064037 --- /dev/null +++ b/src/test/java/holland/andres/DebitAccountTest.java @@ -0,0 +1,51 @@ +package holland.andres; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class DebitAccountTest { + + @Test + public void NoDebitIfBalanceWouldGoNegativeAndOverdraftEnabled () { + Account account1 = new Account("Tariq","checking","enabled",0); + DebitAccount debitAccount = new DebitAccount(); + boolean actual = debitAccount.debit(account1, 10); + assertEquals(false, actual); + } + + @Test + public void DebitIfBalanceWouldGoNegativeAndOverdraftDisabled () { + Account account1 = new Account("Tariq","checking","disabled",0); + DebitAccount debitAccount = new DebitAccount(); + boolean actual = debitAccount.debit(account1, 10); + assertEquals(true, actual); + } + + @Test + public void DebitOpenAccount () { + Account account1 = new Account("Tariq","checking","disabled",0); + DebitAccount debitAccount = new DebitAccount(); + boolean actual = debitAccount.debit(account1, 10); + assertEquals(true, actual); + } + + @Test + public void DebitClosedAccount () { + Account account1 = new Account("Tariq","checking","disabled",0); + DebitAccount debitAccount = new DebitAccount(); + account1.setAccountStatus("closed"); + boolean actual = debitAccount.debit(account1, 10); + assertEquals(false, actual); + } + + @Test + public void DebitFrozenAccount () { + Account account1 = new Account("Tariq","checking","disabled",0); + DebitAccount debitAccount = new DebitAccount(); + account1.setAccountStatus("frozen"); + boolean actual = debitAccount.debit(account1, 10); + assertEquals(false, actual); + } + +} \ No newline at end of file diff --git a/target/classes/holland/andres/Account.class b/target/classes/holland/andres/Account.class new file mode 100644 index 0000000..71aa3dd Binary files /dev/null and b/target/classes/holland/andres/Account.class differ diff --git a/target/classes/holland/andres/BalanceInquiry.class b/target/classes/holland/andres/BalanceInquiry.class new file mode 100644 index 0000000..290fb95 Binary files /dev/null and b/target/classes/holland/andres/BalanceInquiry.class differ diff --git a/target/classes/holland/andres/ChangeName.class b/target/classes/holland/andres/ChangeName.class new file mode 100644 index 0000000..b9de463 Binary files /dev/null and b/target/classes/holland/andres/ChangeName.class differ diff --git a/target/classes/holland/andres/CloseAccount.class b/target/classes/holland/andres/CloseAccount.class new file mode 100644 index 0000000..e010426 Binary files /dev/null and b/target/classes/holland/andres/CloseAccount.class differ diff --git a/target/classes/holland/andres/CreditAccount.class b/target/classes/holland/andres/CreditAccount.class new file mode 100644 index 0000000..2249106 Binary files /dev/null and b/target/classes/holland/andres/CreditAccount.class differ diff --git a/target/classes/holland/andres/DebitAccount.class b/target/classes/holland/andres/DebitAccount.class new file mode 100644 index 0000000..80654c8 Binary files /dev/null and b/target/classes/holland/andres/DebitAccount.class differ diff --git a/target/classes/holland/andres/Main.class b/target/classes/holland/andres/Main.class new file mode 100644 index 0000000..51cd9fe Binary files /dev/null and b/target/classes/holland/andres/Main.class differ diff --git a/target/test-classes/holland/andres/AccountTest.class b/target/test-classes/holland/andres/AccountTest.class new file mode 100644 index 0000000..d1282da Binary files /dev/null and b/target/test-classes/holland/andres/AccountTest.class differ diff --git a/target/test-classes/holland/andres/ChangeNameTest.class b/target/test-classes/holland/andres/ChangeNameTest.class new file mode 100644 index 0000000..ba41588 Binary files /dev/null and b/target/test-classes/holland/andres/ChangeNameTest.class differ diff --git a/target/test-classes/holland/andres/CloseAccountTest.class b/target/test-classes/holland/andres/CloseAccountTest.class new file mode 100644 index 0000000..f53126b Binary files /dev/null and b/target/test-classes/holland/andres/CloseAccountTest.class differ diff --git a/target/test-classes/holland/andres/CreditAccountTest.class b/target/test-classes/holland/andres/CreditAccountTest.class new file mode 100644 index 0000000..62f2845 Binary files /dev/null and b/target/test-classes/holland/andres/CreditAccountTest.class differ diff --git a/target/test-classes/holland/andres/DebitAccountTest.class b/target/test-classes/holland/andres/DebitAccountTest.class new file mode 100644 index 0000000..c79c412 Binary files /dev/null and b/target/test-classes/holland/andres/DebitAccountTest.class differ