Eric Foster 8 år sedan
förälder
incheckning
03c16a9944

+ 13
- 0
.idea/libraries/Maven__junit_junit_4_12.xml Visa fil

@@ -0,0 +1,13 @@
1
+<component name="libraryTable">
2
+  <library name="Maven: junit:junit:4.12">
3
+    <CLASSES>
4
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
5
+    </CLASSES>
6
+    <JAVADOC>
7
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-javadoc.jar!/" />
8
+    </JAVADOC>
9
+    <SOURCES>
10
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-sources.jar!/" />
11
+    </SOURCES>
12
+  </library>
13
+</component>

+ 13
- 0
.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml Visa fil

@@ -0,0 +1,13 @@
1
+<component name="libraryTable">
2
+  <library name="Maven: org.hamcrest:hamcrest-core:1.3">
3
+    <CLASSES>
4
+      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
5
+    </CLASSES>
6
+    <JAVADOC>
7
+      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-javadoc.jar!/" />
8
+    </JAVADOC>
9
+    <SOURCES>
10
+      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar!/" />
11
+    </SOURCES>
12
+  </library>
13
+</component>

+ 1
- 0
.idea/modules.xml Visa fil

@@ -3,6 +3,7 @@
3 3
   <component name="ProjectModuleManager">
4 4
     <modules>
5 5
       <module fileurl="file://$PROJECT_DIR$/bankaccountlab.iml" filepath="$PROJECT_DIR$/bankaccountlab.iml" />
6
+      <module fileurl="file://$PROJECT_DIR$/bankaccountlab.iml" filepath="$PROJECT_DIR$/bankaccountlab.iml" />
6 7
     </modules>
7 8
   </component>
8 9
 </project>

+ 479
- 387
.idea/workspace.xml
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


+ 9
- 0
pom.xml Visa fil

@@ -8,5 +8,14 @@
8 8
     <artifactId>bankaccountlab</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10 10
 
11
+    <dependencies>
12
+        <!-- https://mvnrepository.com/artifact/junit/junit -->
13
+        <dependency>
14
+            <groupId>junit</groupId>
15
+            <artifactId>junit</artifactId>
16
+            <version>4.12</version>
17
+            <scope>test</scope>
18
+        </dependency>
19
+    </dependencies>
11 20
 
12 21
 </project>

+ 109
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/ATM.java Visa fil

@@ -0,0 +1,109 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+import java.util.Scanner;
4
+
5
+public class ATM {
6
+    Scanner scanner = new Scanner(System.in);
7
+
8
+    public void runATM(){
9
+        System.out.println("Insert ATM Card");
10
+        String ATMCardNumber = scanner.nextLine();
11
+        AccountHolder[] accountHolders = loadAllAccountHolders();
12
+        AccountHolder accountHolder = lookUpAccountHolder(accountHolders, ATMCardNumber);
13
+        System.out.println("Enter pin number:");
14
+        String pinNumber = scanner.nextLine();
15
+        boolean accountHolderVerified = verifyPinNumber(accountHolder, pinNumber);
16
+
17
+        if(accountHolderVerified) {
18
+            BankAccount[] bankAccounts = loadBankAccounts(accountHolder);
19
+            System.out.println("Which account would you like to access: checking, savings, or business?");
20
+            String accountChoice = scanner.nextLine();
21
+            BankAccount accessedAccount = accessBankAccount(bankAccounts,accountChoice);
22
+            System.out.println("What would you like to do: deposit, withdraw, get balance?");
23
+            String actionChoice = scanner.nextLine();
24
+            performAction(accessedAccount, actionChoice);
25
+            System.out.println("Your balance is now: " + accessedAccount.getBalance());
26
+        }
27
+
28
+        System.out.println("Please insert ATM card again to make another change");
29
+    }
30
+
31
+    public AccountHolder[] loadAllAccountHolders(){
32
+        AccountHolders accountHolders = new AccountHolders();
33
+        accountHolders.loadAccountHolderArrayFromDataBase();
34
+        return accountHolders.getAccountHolderArray();
35
+    }
36
+
37
+    public AccountHolder lookUpAccountHolder(AccountHolder[] accountHolders, String ATMCardNumber){
38
+        for (AccountHolder a : accountHolders){
39
+            if (a.getATMCardNumber().equals(ATMCardNumber)){
40
+                return a;
41
+            }
42
+        }
43
+        return null;
44
+    }
45
+
46
+    public boolean verifyPinNumber(AccountHolder accountHolder, String pinNumber){
47
+        if (accountHolder.getPinNumber().equals(pinNumber)){
48
+            return true;
49
+        } else {
50
+            return false;
51
+        }
52
+    }
53
+
54
+    public BankAccount[] loadBankAccounts(AccountHolder accountHolder){
55
+        return accountHolder.getBankAccountArray();
56
+    }
57
+
58
+    public BankAccount accessBankAccount(BankAccount[] bankAccounts, String accountType) {
59
+        if(accountType.equals("checking")){
60
+            for (BankAccount b : bankAccounts){
61
+                if (b instanceof CheckingAccount){
62
+                    return b;
63
+                }
64
+            }
65
+        } else if (accountType.equals("savings")){
66
+            for (BankAccount b : bankAccounts){
67
+                if (b instanceof SavingsAccount){
68
+                    return b;
69
+                }
70
+            }
71
+        } else {
72
+            for (BankAccount b : bankAccounts){
73
+                if (b instanceof BusinessAccount) {
74
+                    return b;
75
+                }
76
+            }
77
+        }
78
+        return null;
79
+    }
80
+
81
+    public Double performAction(BankAccount bankAccount, String actionChoice){
82
+        if(actionChoice.equals("deposit")){
83
+            System.out.println("How much would you like to deposit?");
84
+            Double depositAmount = Double.parseDouble(scanner.nextLine());
85
+            Double newBalance = depositToAccount(bankAccount, depositAmount);
86
+        } else if (actionChoice.equals("withdraw")) {
87
+            System.out.println("How much would you like to withdraw?");
88
+            Double withdrawAmount = Double.parseDouble(scanner.nextLine());
89
+            Double newBalance = withdrawFromAccount(bankAccount, withdrawAmount);
90
+        }
91
+        return bankAccount.getBalance();
92
+    }
93
+
94
+    public Double depositToAccount(BankAccount bankAccount, Double depositAmount){
95
+        bankAccount.deposit(depositAmount);
96
+        return bankAccount.getBalance();
97
+    }
98
+
99
+    public Double withdrawFromAccount(BankAccount bankAccount, Double withdrawAmount){
100
+        bankAccount.withdraw(withdrawAmount);
101
+        return bankAccount.getBalance();
102
+    }
103
+
104
+    public Double getBalanceFromAccount(BankAccount bankAccount){
105
+        return bankAccount.getBalance();
106
+    }
107
+
108
+
109
+}

+ 43
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/AccountHolder.java Visa fil

@@ -0,0 +1,43 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class AccountHolder {
4
+    private String name;
5
+    private String ATMCardNumber;
6
+    private String pinNumber;
7
+    private BankAccount[] bankAccountArray;
8
+
9
+    public AccountHolder(String name, String ATMCardNumber, String pinNumber, BankAccount... bankAccounts){
10
+        this.name = name;
11
+        this.ATMCardNumber = ATMCardNumber;
12
+        this.pinNumber = pinNumber;
13
+        this.bankAccountArray = bankAccounts;
14
+    }
15
+
16
+    public String getName() {
17
+        return name;
18
+    }
19
+
20
+    public void setName(String name) {
21
+        this.name = name;
22
+    }
23
+
24
+    public String getPinNumber() {
25
+        return pinNumber;
26
+    }
27
+
28
+    public void setPinNumber(String pinNumber) {
29
+        this.pinNumber = pinNumber;
30
+    }
31
+
32
+    public String getATMCardNumber() {
33
+        return ATMCardNumber;
34
+    }
35
+
36
+    public void setATMCardNumber(String ATMCardNumber) {
37
+        this.ATMCardNumber = ATMCardNumber;
38
+    }
39
+
40
+    public BankAccount[] getBankAccountArray() {
41
+        return bankAccountArray;
42
+    }
43
+}

+ 23
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/AccountHolders.java Visa fil

@@ -0,0 +1,23 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class AccountHolders {
4
+    private AccountHolder[] accountOwnerArray;
5
+
6
+    public AccountHolder[] getAccountHolderArray() {
7
+        return accountOwnerArray;
8
+    }
9
+
10
+    public void loadAccountHolderArrayFromDataBase() {
11
+        accountOwnerArray = new AccountHolder[5];
12
+        accountOwnerArray[0] = new AccountHolder("eric", "abc","1234",
13
+                new CheckingAccount("001",200.0), new SavingsAccount("002", 1000.0), new BusinessAccount("010", 2000.0));
14
+        accountOwnerArray[1] = new AccountHolder("tyler", "bcd", "2345",
15
+                new CheckingAccount("003", 500.0), new BusinessAccount("004", 10000.0));
16
+        accountOwnerArray[2] = new AccountHolder("jane", "efg","3456",
17
+                new SavingsAccount("005", 400.0));
18
+        accountOwnerArray[3] = new AccountHolder("bill", "hij", "4567",
19
+                new CheckingAccount("006", 7000.0), new SavingsAccount("007", 10000.0));
20
+        accountOwnerArray[4] = new AccountHolder("marion", "klm","5678",
21
+                new SavingsAccount("008", 3000.0), new BusinessAccount("009", 2000.0));
22
+    }
23
+}

+ 31
- 4
src/main/java/com/zipcodewilmington/bankaccountlab/BankAccount.java Visa fil

@@ -1,7 +1,34 @@
1 1
 package com.zipcodewilmington.bankaccountlab;
2 2
 
3
-/**
4
- * Created by leon on 1/10/18.
5
- */
6
-public class BankAccount {
3
+public abstract class BankAccount {
4
+    private String accountNumber;
5
+    private Double balance;
6
+
7
+    public BankAccount(){}
8
+
9
+    public BankAccount(String accountNumber, Double balance){
10
+        this.accountNumber = accountNumber;
11
+        this.balance = balance;
12
+    }
13
+
14
+    public String getAccountNumber() {
15
+        return accountNumber;
16
+    }
17
+
18
+    public void setAccountNumber(String accountNumber) {
19
+        this.accountNumber = accountNumber;
20
+    }
21
+
22
+    public Double getBalance(){
23
+        return balance;
24
+    }
25
+
26
+    public void withdraw(Double withdrawal){
27
+        balance -= withdrawal;
28
+    }
29
+
30
+    public void deposit(Double deposit){
31
+        balance += deposit;
32
+    }
33
+
7 34
 }

+ 7
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/BusinessAccount.java Visa fil

@@ -0,0 +1,7 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class BusinessAccount extends BankAccount {
4
+    BusinessAccount(String accountNumber, Double balance){
5
+        super(accountNumber, balance);
6
+    }
7
+}

+ 7
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/CheckingAccount.java Visa fil

@@ -0,0 +1,7 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class CheckingAccount extends BankAccount {
4
+    CheckingAccount(String accountNumber, Double balance){
5
+        super(accountNumber, balance);
6
+    }
7
+}

+ 4
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/MainApplication.java Visa fil

@@ -4,4 +4,8 @@ package com.zipcodewilmington.bankaccountlab;
4 4
  * Created by leon on 1/10/18.
5 5
  */
6 6
 public class MainApplication {
7
+    public static void main(String[] args){
8
+        ATM atm = new ATM();
9
+        atm.runATM();
10
+    }
7 11
 }

+ 7
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/SavingsAccount.java Visa fil

@@ -0,0 +1,7 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class SavingsAccount extends BankAccount {
4
+    SavingsAccount(String accountNumber, Double balance){
5
+        super(accountNumber, balance);
6
+    }
7
+}

+ 131
- 0
src/test/java/com/zipcodewilmington/bankaccountlab/ATMTest.java Visa fil

@@ -0,0 +1,131 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.*;
6
+
7
+public class ATMTest {
8
+
9
+    //Start ATM
10
+    public void runATMTest() {
11
+    }
12
+
13
+    //Load all account holders to atm
14
+    @Test
15
+    public void loadAllAccountHoldersTest(){
16
+        //Given
17
+        ATM atm = new ATM();
18
+        AccountHolder[] accountHolders = atm.loadAllAccountHolders();
19
+        //Actual
20
+        boolean actual = accountHolders instanceof AccountHolder[];
21
+        //Test
22
+        assertTrue(actual);
23
+    }
24
+
25
+    //Look up Account by Account number
26
+    @Test
27
+    public void lookUpAccountHolderTest(){
28
+        //Given
29
+        ATM atm = new ATM();
30
+        AccountHolder[] accountHolders = atm.loadAllAccountHolders();
31
+        String ATMCardNumber = "abc";
32
+        //Actual
33
+        AccountHolder actual = atm.lookUpAccountHolder(accountHolders, ATMCardNumber);
34
+        //Expected
35
+        AccountHolder expected = accountHolders[0];
36
+        //Test
37
+        assertEquals(expected,actual);
38
+    }
39
+
40
+    //Verify pin number of account
41
+    @Test
42
+    public void verifyPinNumberTest(){
43
+        //Given
44
+        ATM atm = new ATM();
45
+        AccountHolder[] accountHolders = atm.loadAllAccountHolders();
46
+        AccountHolder testAccountHolder = atm.lookUpAccountHolder(accountHolders,"abc");
47
+        String pinNumber = "1234";
48
+        //Actual
49
+        Boolean actual = atm.verifyPinNumber(testAccountHolder, pinNumber);
50
+        //Test
51
+        assertTrue(actual);
52
+    }
53
+
54
+    //Load all bank accounts for account holder
55
+    @Test
56
+    public void loadBankAccountsTest(){
57
+        //Given
58
+        ATM atm = new ATM();
59
+        AccountHolder[] accountHolders = atm.loadAllAccountHolders();
60
+        AccountHolder testAccountHolder = accountHolders[0];
61
+        BankAccount[] testBankAccounts = atm.loadBankAccounts(testAccountHolder);
62
+        //Actual
63
+        boolean actual = testBankAccounts instanceof BankAccount[];
64
+        //Test
65
+        assertTrue(actual);
66
+    }
67
+
68
+    //Access bank account based on account type (each account holder can only
69
+    //have 1 instance of each type
70
+    @Test
71
+    public void accessBankAccountTest(){
72
+        //Given
73
+        ATM atm = new ATM();
74
+        AccountHolder[] accountHolders = atm.loadAllAccountHolders();
75
+        AccountHolder testAccountHolder = accountHolders[0];
76
+        BankAccount[] testBankAccounts = atm.loadBankAccounts(testAccountHolder);
77
+        BankAccount testBankAccount = atm.accessBankAccount(testBankAccounts, "checking");
78
+        //Actual
79
+        boolean actual = testBankAccount instanceof CheckingAccount;
80
+        //Test
81
+        assertTrue(actual);
82
+    }
83
+
84
+    //Deposit to account of choice
85
+    @Test
86
+    public void depositToAccountTest(){
87
+        //Given
88
+        ATM atm = new ATM();
89
+        AccountHolder[] accountHolders = atm.loadAllAccountHolders();
90
+        AccountHolder testAccountHolder = accountHolders[0];
91
+        BankAccount[] testBankAccounts = atm.loadBankAccounts(testAccountHolder);
92
+        BankAccount testBankAccount = atm.accessBankAccount(testBankAccounts, "checking");
93
+        Double actual = atm.depositToAccount(testBankAccount, 100.0);
94
+        //Expected
95
+        Double expected = 300.0;
96
+        //Test
97
+        assertEquals(actual, expected);
98
+    }
99
+
100
+    //Withdraw from account of choice
101
+    @Test
102
+    public void withdrawFromAccountTest(){
103
+        //Given
104
+        ATM atm = new ATM();
105
+        AccountHolder[] accountHolders = atm.loadAllAccountHolders();
106
+        AccountHolder testAccountHolder = accountHolders[0];
107
+        BankAccount[] testBankAccounts = atm.loadBankAccounts(testAccountHolder);
108
+        BankAccount testBankAccount = atm.accessBankAccount(testBankAccounts, "checking");
109
+        Double actual = atm.withdrawFromAccount(testBankAccount, 100.0);
110
+        //Expected
111
+        Double expected = 100.0;
112
+        //Test
113
+        assertEquals(actual, expected);
114
+    }
115
+
116
+    //Get Balance of account of choice
117
+    @Test
118
+    public void getBalanceFromAccountTest(){
119
+        //Given
120
+        ATM atm = new ATM();
121
+        AccountHolder[] accountHolders = atm.loadAllAccountHolders();
122
+        AccountHolder testAccountHolder = accountHolders[0];
123
+        BankAccount[] testBankAccounts = atm.loadBankAccounts(testAccountHolder);
124
+        BankAccount testBankAccount = atm.accessBankAccount(testBankAccounts, "checking");
125
+        Double actual = atm.getBalanceFromAccount(testBankAccount);
126
+        //Expected
127
+        Double expected = 200.0;
128
+        //Test
129
+        assertEquals(actual, expected);
130
+    }
131
+}

+ 45
- 0
src/test/java/com/zipcodewilmington/bankaccountlab/BankAccountTest.java Visa fil

@@ -1,7 +1,52 @@
1 1
 package com.zipcodewilmington.bankaccountlab;
2 2
 
3
+import org.junit.Test;
4
+import static org.junit.Assert.*;
5
+
3 6
 /**
4 7
  * Created by leon on 1/10/18.
5 8
  */
6 9
 public class BankAccountTest {
10
+
11
+    BankAccount testBankAccount1 = new CheckingAccount("001", 200.0);
12
+    BankAccount testBankAccount2 = new SavingsAccount("002", 1000.0);
13
+    BankAccount testBankAccount3 = new BusinessAccount("010", 2000.0);
14
+
15
+    @Test
16
+    public void getAccountNumberTest() {
17
+        String actual = testBankAccount1.getAccountNumber();
18
+        String expected = "001";
19
+        assertEquals(expected, actual);
20
+    }
21
+
22
+    @Test
23
+    public void setAccountNumberTest() {
24
+        String expected = "333";
25
+        testBankAccount2.setAccountNumber(expected);
26
+        String actual = testBankAccount2.getAccountNumber();
27
+        assertEquals(expected,actual);
28
+    }
29
+
30
+    @Test
31
+    public void getBalanceTest(){
32
+        Double actual = testBankAccount3.getBalance();
33
+        Double expected = 2000.0;
34
+        assertEquals(expected, actual);
35
+    }
36
+
37
+    @Test
38
+    public void withdrawTest(){
39
+        testBankAccount1.withdraw(100.0);
40
+        Double actual = testBankAccount1.getBalance();
41
+        Double expected = 100.0;
42
+        assertEquals(expected,actual);
43
+    }
44
+
45
+    @Test
46
+    public void depositTest(){
47
+        testBankAccount2.deposit(200.0);
48
+        Double actual = testBankAccount2.getBalance();
49
+        Double expected = 1200.0;
50
+        assertEquals(expected,actual);
51
+    }
7 52
 }