Browse Source

tests passing

Chad 8 years ago
parent
commit
8afac7db9d

+ 13
- 0
.idea/libraries/Maven__junit_junit_4_12.xml View File

@@ -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_apiguardian_apiguardian_api_1_0_0.xml View File

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

+ 13
- 0
.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml View File

@@ -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>

+ 13
- 0
.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_2_0.xml View File

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

+ 13
- 0
.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_2_0.xml View File

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

+ 13
- 0
.idea/libraries/Maven__org_opentest4j_opentest4j_1_1_0.xml View File

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

+ 1
- 62
.idea/misc.xml View File

@@ -61,68 +61,7 @@
61 61
       </profile-state>
62 62
     </entry>
63 63
   </component>
64
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
64
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="10" project-jdk-type="JavaSDK">
65 65
     <output url="file://$PROJECT_DIR$/out" />
66 66
   </component>
67
-  <component name="masterDetails">
68
-    <states>
69
-      <state key="GlobalLibrariesConfigurable.UI">
70
-        <settings>
71
-          <splitter-proportions>
72
-            <option name="proportions">
73
-              <list>
74
-                <option value="0.2" />
75
-              </list>
76
-            </option>
77
-          </splitter-proportions>
78
-        </settings>
79
-      </state>
80
-      <state key="JdkListConfigurable.UI">
81
-        <settings>
82
-          <last-edited>1.8</last-edited>
83
-          <splitter-proportions>
84
-            <option name="proportions">
85
-              <list>
86
-                <option value="0.2" />
87
-              </list>
88
-            </option>
89
-          </splitter-proportions>
90
-        </settings>
91
-      </state>
92
-      <state key="ProjectJDKs.UI">
93
-        <settings>
94
-          <last-edited>1.8</last-edited>
95
-          <splitter-proportions>
96
-            <option name="proportions">
97
-              <list>
98
-                <option value="0.2" />
99
-              </list>
100
-            </option>
101
-          </splitter-proportions>
102
-        </settings>
103
-      </state>
104
-      <state key="ProjectLibrariesConfigurable.UI">
105
-        <settings>
106
-          <splitter-proportions>
107
-            <option name="proportions">
108
-              <list>
109
-                <option value="0.2" />
110
-              </list>
111
-            </option>
112
-          </splitter-proportions>
113
-        </settings>
114
-      </state>
115
-      <state key="ScopeChooserConfigurable.UI">
116
-        <settings>
117
-          <splitter-proportions>
118
-            <option name="proportions">
119
-              <list>
120
-                <option value="0.2" />
121
-              </list>
122
-            </option>
123
-          </splitter-proportions>
124
-        </settings>
125
-      </state>
126
-    </states>
127
-  </component>
128 67
 </project>

+ 1
- 0
.idea/modules.xml View File

@@ -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>

+ 606
- 377
.idea/workspace.xml
File diff suppressed because it is too large
View File


+ 14
- 0
pom.xml View File

@@ -7,6 +7,20 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>bankaccountlab</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>org.junit.jupiter</groupId>
13
+            <artifactId>junit-jupiter-api</artifactId>
14
+            <version>RELEASE</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+        <dependency>
18
+            <groupId>junit</groupId>
19
+            <artifactId>junit</artifactId>
20
+            <version>RELEASE</version>
21
+            <scope>test</scope>
22
+        </dependency>
23
+    </dependencies>
10 24
 
11 25
 
12 26
 </project>

+ 127
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/ATM.java View File

@@ -0,0 +1,127 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+
4
+public class ATM {
5
+    Console console = new Console();
6
+    BankAccount account1;
7
+    BankAccount account2;
8
+    BankAccount account3;
9
+    BankAccount[] accounts = new BankAccount[]{account1,account2,account3};
10
+
11
+    public ATM(){
12
+
13
+    }
14
+
15
+    public BankAccount[] getAccounts() {
16
+        return accounts;
17
+    }
18
+
19
+    public void setAccounts(BankAccount[] accounts) {
20
+        this.accounts = accounts;
21
+    }
22
+
23
+    public void runATM(){
24
+        console.println("Welcome to the ATM! You may type \"leave\" at any word entry to close the application");
25
+        createAccounts();
26
+
27
+        boolean run =true;
28
+        while(run) {
29
+            console.println("Here are your current accounts:");
30
+            for (BankAccount account : accounts) {
31
+                console.println("\nOwner Name: " + account.getOwnerName()+"\nAccount Number: "+ account.getAccountNumber() + "\nCurrent Balance: " + account.getCurrentBalance());
32
+            }
33
+            int currentAccount = console.getIntInput("please enter your account number");
34
+
35
+            switch(console.getIntInput("What would you like to do?\n1.Transfer Funds\n2.Change An Account Owner\n")){
36
+                case (1) : transferFunds(currentAccount);
37
+                break;
38
+                case (2) : changeAccountOwner(currentAccount,console.getStringInput("What is the new name on the account?"));
39
+                break;
40
+                default:
41
+                console.println("Please enter the number associated with your choice");
42
+            }
43
+        }
44
+    }
45
+
46
+    public void transferFunds(int account){
47
+        switch (console.getIntInput("What would you like to do?\n1.Deposit\n2.Withdraw\n3.Transfer to a different account")){
48
+            case (1) : deposit(account, console.getDoubleInput("How much would you like to deposit?"));
49
+                break;
50
+            case (2) : withdraw(account,console.getDoubleInput("How much would you like to withdraw?"));
51
+                break;
52
+            case (3) : transfer(account,console.getDoubleInput("How much would you like to transfer?"),console.getIntInput("Enter the account number you would like to transfer to"));
53
+                break;
54
+            default:
55
+                console.println("Please enter the number associated with your choice");
56
+
57
+        }
58
+    }
59
+
60
+    public void withdraw(int currentAccount, double amount) {
61
+        for (BankAccount account : accounts) {
62
+            if (currentAccount == account.getAccountNumber()){
63
+                account.setCurrentBalance(account.getCurrentBalance()-amount);
64
+            }
65
+        }
66
+    }
67
+
68
+    public void deposit(int currentAccount, double amount) {
69
+        for (BankAccount account : accounts) {
70
+            if (currentAccount == account.getAccountNumber()){
71
+                account.setCurrentBalance(account.getCurrentBalance()+amount);
72
+            }
73
+        }
74
+    }
75
+
76
+    public void transfer(int currentAccount, double amount, int transferTo) {
77
+
78
+        for (BankAccount account : accounts) {
79
+            if (currentAccount == account.getAccountNumber()){
80
+                account.setCurrentBalance(account.getCurrentBalance()-amount);
81
+            }
82
+            if (transferTo == account.getAccountNumber()){
83
+                account.setCurrentBalance(account.getCurrentBalance()+amount);
84
+
85
+            }
86
+        }
87
+    }
88
+
89
+    public void changeAccountOwner(int currentAccount, String newName){
90
+        for (BankAccount account : accounts) {
91
+            if (currentAccount == account.getAccountNumber()){
92
+                account.setOwnerName(newName);
93
+            }
94
+        }
95
+    }
96
+
97
+    public void createAccounts() {
98
+
99
+        for (BankAccount account : accounts) {
100
+            boolean creating = true;
101
+            while (creating) {
102
+                switch (console.getIntInput("What kind of account would you like to open?\n1.Business\n2.Checking\n3.Savings\n4.Skip")) {
103
+                    case (1):
104
+                        account = new BusinessAccount(console.getDoubleInput("How much would you like to deposit?"), console.getStringInput("What is your name?"));
105
+                        creating = false;
106
+                        break;
107
+                    case (2):
108
+                        account = new CheckingAccount(console.getDoubleInput("How much would you like to deposit?"), console.getStringInput("What is your name?"));
109
+                        creating = false;
110
+                        break;
111
+                    case (3):
112
+                        account = new SavingsAccount(console.getDoubleInput("How much would you like to deposit?"), console.getStringInput("What is your name?"));
113
+                        creating = false;
114
+                        break;
115
+                    case (4):
116
+                        account = null;
117
+                        creating = false;
118
+                        break;
119
+                    default:
120
+                        console.println("Please enter the number associated with your choice");
121
+                }
122
+            }
123
+        }
124
+    }
125
+
126
+
127
+}

+ 41
- 1
src/main/java/com/zipcodewilmington/bankaccountlab/BankAccount.java View File

@@ -1,7 +1,47 @@
1 1
 package com.zipcodewilmington.bankaccountlab;
2 2
 
3
+import java.util.Random;
4
+
3 5
 /**
4 6
  * Created by leon on 1/10/18.
5 7
  */
6
-public class BankAccount {
8
+public abstract class BankAccount {
9
+    Random random = new Random();
10
+    Double currentBalance;
11
+    Integer accountNumber;
12
+    String ownerName;
13
+
14
+    public BankAccount(Double currentBalance, String ownerName) {
15
+        this.currentBalance = currentBalance;
16
+        this.accountNumber = 100000000  + random.nextInt(900000000);
17
+        this.ownerName = ownerName;
18
+    }
19
+
20
+    public BankAccount(){
21
+
22
+    }
23
+
24
+    public Integer getAccountNumber() {
25
+        return accountNumber;
26
+    }
27
+
28
+    public void setAccountNumber(Integer accountNumber) {
29
+        this.accountNumber = accountNumber;
30
+    }
31
+
32
+    public String getOwnerName() {
33
+        return ownerName;
34
+    }
35
+
36
+    public void setOwnerName(String ownerName) {
37
+        this.ownerName = ownerName;
38
+    }
39
+
40
+    public Double getCurrentBalance() {
41
+        return currentBalance;
42
+    }
43
+
44
+    public void setCurrentBalance(Double currentBalance) {
45
+        this.currentBalance = currentBalance;
46
+    }
7 47
 }

+ 9
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/BusinessAccount.java View File

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

+ 10
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/CheckingAccount.java View File

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

+ 75
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/Console.java View File

@@ -0,0 +1,75 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+import java.util.Scanner;
4
+
5
+public class Console {
6
+
7
+        public void print(String output, Object... args) {
8
+            System.out.printf(output, args);
9
+        }
10
+
11
+        public void println(String output, Object... args) {
12
+            print(output + "\n", args);
13
+        }
14
+
15
+        public String getStringInput(String prompt) {
16
+            Scanner scanner = new Scanner(System.in);
17
+            println(prompt);
18
+            String userInput = scanner.nextLine();
19
+            String userInput2 = userInput.toLowerCase();
20
+            if (userInput2.equals("leave")) {
21
+                System.out.print("Please reinitialize the program");
22
+                System.exit(0);
23
+            }
24
+            return userInput2;
25
+        }
26
+
27
+
28
+        public Integer getIntInput(String prompt) {
29
+            int b = 0;
30
+            boolean good = false;
31
+            println(prompt);
32
+            while (good == false) {
33
+                Scanner scannerB = new Scanner(System.in);
34
+                if (scannerB.hasNextInt()) {
35
+                    b = scannerB.nextInt();
36
+                    good = true;
37
+                } else {
38
+                    System.out.print("Invalid input please start over\n");
39
+                }
40
+            }
41
+            return b;
42
+        }
43
+
44
+    public Double getDoubleInput(String prompt) {
45
+        double b = 0;
46
+        boolean good = false;
47
+        println(prompt);
48
+        while (good == false) {
49
+            Scanner scannerB = new Scanner(System.in);
50
+            if (scannerB.hasNextDouble()) {
51
+                b = scannerB.nextDouble();
52
+                good = true;
53
+            } else {
54
+                System.out.print("Invalid input please start over\n");
55
+            }
56
+        }
57
+        return b;
58
+    }
59
+
60
+        public String yesOrNo(String prompt) {
61
+            boolean good = false;
62
+            String correct = "";
63
+            while (good == false) {
64
+                String answer = getStringInput(prompt);
65
+                if (answer.equalsIgnoreCase("yes") || answer.equalsIgnoreCase("no")) {
66
+                    good = true;
67
+                    correct = answer;
68
+                } else {
69
+                    println("what was that? Please say yes or no.");
70
+                }
71
+            }
72
+            return correct;
73
+        }
74
+}
75
+

+ 3
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/MainApplication.java View File

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

+ 9
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/SavingsAccount.java View File

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

+ 92
- 0
src/test/java/com/zipcodewilmington/bankaccountlab/ATMTest.java View File

@@ -0,0 +1,92 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+import org.junit.*;
4
+import org.junit.jupiter.api.Test;
5
+
6
+
7
+public class ATMTest {
8
+    ATM test =new ATM();
9
+    CheckingAccount chadsChecking = new CheckingAccount(500.00, "Chad Hallinan");
10
+    BusinessAccount chadsBusiness = new BusinessAccount(500.00,"Chad Hallinan");
11
+    SavingsAccount chadsSavings= new SavingsAccount(500.00,"Chad Hallinan");
12
+    BankAccount[] chads = new BankAccount[]{chadsChecking,chadsBusiness,chadsSavings};
13
+
14
+    public ATMTest()
15
+    {
16
+    }
17
+
18
+    /**
19
+     * Sets up the test fixture.
20
+     *
21
+     * Called before every test case method.
22
+     */
23
+    @Before
24
+    public void setUp()
25
+    {
26
+
27
+    }
28
+
29
+    @Test
30
+    public void withdrawTest(){
31
+        //Given
32
+        test.setAccounts(chads);
33
+        test.withdraw(chadsChecking.getAccountNumber(), 300);
34
+        //When
35
+        double expected= 200;
36
+        double actual = chadsChecking.getCurrentBalance();
37
+        //Result
38
+        Assert.assertEquals(expected, actual, 0);
39
+
40
+    }
41
+
42
+    @Test
43
+    public void depositTest(){
44
+        //Given
45
+        test.setAccounts(chads);
46
+        test.deposit(chadsChecking.getAccountNumber(), 300);
47
+        //When
48
+        double expected= 800;
49
+        double actual = chadsChecking.getCurrentBalance();
50
+        //Result
51
+        Assert.assertEquals(expected, actual, 0);
52
+
53
+    }
54
+
55
+    @Test
56
+    public void transferTest(){
57
+        //Given
58
+        test.setAccounts(chads);
59
+        test.transfer(chadsChecking.getAccountNumber(), 300, chadsSavings.getAccountNumber());
60
+        //When
61
+        double expected= 800;
62
+        double actual = chadsSavings.getCurrentBalance();
63
+        //Result
64
+        Assert.assertEquals(expected, actual, 0);
65
+
66
+    }
67
+
68
+    @Test
69
+    public void changeAccountOwnerTest(){
70
+        //Given
71
+        test.setAccounts(chads);
72
+        test.changeAccountOwner(chadsChecking.getAccountNumber(), "Sean Hallinan");
73
+        //When
74
+        String expected= "Sean Hallinan";
75
+        String actual = chadsChecking.getOwnerName();
76
+        //Result
77
+        Assert.assertEquals(expected, actual);
78
+
79
+    }
80
+
81
+
82
+
83
+    /**
84
+     * Tears down the test fixture.
85
+     *
86
+     * Called after every test case method.
87
+     */
88
+    @After
89
+    public void tearDown()
90
+    {
91
+    }
92
+}

+ 4
- 0
src/test/java/com/zipcodewilmington/bankaccountlab/BusinessAccountTest.java View File

@@ -0,0 +1,4 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class BusinessAccountTest {
4
+}

+ 4
- 0
src/test/java/com/zipcodewilmington/bankaccountlab/CheckingAccountTest.java View File

@@ -0,0 +1,4 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class CheckingAccountTest {
4
+}

+ 4
- 0
src/test/java/com/zipcodewilmington/bankaccountlab/SavingsAccountTest.java View File

@@ -0,0 +1,4 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class SavingsAccountTest {
4
+}