Browse Source

TG complete

Tennessee Gibbs 8 years ago
parent
commit
f2833464e7

+ 1
- 0
.idea/.name View File

@@ -0,0 +1 @@
1
+bankaccountlab

+ 1
- 1
.idea/compiler.xml View File

@@ -9,7 +9,7 @@
9 9
         <module name="bankaccountlab" />
10 10
       </profile>
11 11
     </annotationProcessing>
12
-    <bytecodeTargetLevel target="1.8">
12
+    <bytecodeTargetLevel>
13 13
       <module name="bankaccountlab" target="1.5" />
14 14
     </bytecodeTargetLevel>
15 15
   </component>

+ 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_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>

+ 2
- 117
.idea/misc.xml View File

@@ -1,43 +1,5 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <project version="4">
3
-  <component name="ClientPropertiesManager">
4
-    <properties class="javax.swing.AbstractButton">
5
-      <property name="hideActionText" class="java.lang.Boolean" />
6
-    </properties>
7
-    <properties class="javax.swing.JComponent">
8
-      <property name="html.disable" class="java.lang.Boolean" />
9
-    </properties>
10
-    <properties class="javax.swing.JEditorPane">
11
-      <property name="JEditorPane.w3cLengthUnits" class="java.lang.Boolean" />
12
-      <property name="JEditorPane.honorDisplayProperties" class="java.lang.Boolean" />
13
-      <property name="charset" class="java.lang.String" />
14
-    </properties>
15
-    <properties class="javax.swing.JList">
16
-      <property name="List.isFileList" class="java.lang.Boolean" />
17
-    </properties>
18
-    <properties class="javax.swing.JPasswordField">
19
-      <property name="JPasswordField.cutCopyAllowed" class="java.lang.Boolean" />
20
-    </properties>
21
-    <properties class="javax.swing.JSlider">
22
-      <property name="Slider.paintThumbArrowShape" class="java.lang.Boolean" />
23
-      <property name="JSlider.isFilled" class="java.lang.Boolean" />
24
-    </properties>
25
-    <properties class="javax.swing.JTable">
26
-      <property name="Table.isFileList" class="java.lang.Boolean" />
27
-      <property name="JTable.autoStartsEdit" class="java.lang.Boolean" />
28
-      <property name="terminateEditOnFocusLost" class="java.lang.Boolean" />
29
-    </properties>
30
-    <properties class="javax.swing.JToolBar">
31
-      <property name="JToolBar.isRollover" class="java.lang.Boolean" />
32
-    </properties>
33
-    <properties class="javax.swing.JTree">
34
-      <property name="JTree.lineStyle" class="java.lang.String" />
35
-    </properties>
36
-    <properties class="javax.swing.text.JTextComponent">
37
-      <property name="caretAspectRatio" class="java.lang.Double" />
38
-      <property name="caretWidth" class="java.lang.Integer" />
39
-    </properties>
40
-  </component>
41 3
   <component name="MavenProjectsManager">
42 4
     <option name="originalFiles">
43 5
       <list>
@@ -45,84 +7,7 @@
45 7
       </list>
46 8
     </option>
47 9
   </component>
48
-  <component name="ProjectInspectionProfilesVisibleTreeState">
49
-    <entry key="Project Default">
50
-      <profile-state>
51
-        <expanded-state>
52
-          <State>
53
-            <id />
54
-          </State>
55
-        </expanded-state>
56
-        <selected-state>
57
-          <State>
58
-            <id>Android</id>
59
-          </State>
60
-        </selected-state>
61
-      </profile-state>
62
-    </entry>
63
-  </component>
64
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
65
-    <output url="file://$PROJECT_DIR$/out" />
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>
10
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_9" project-jdk-name="9" project-jdk-type="JavaSDK">
11
+    <output url="file://$PROJECT_DIR$/classes" />
127 12
   </component>
128 13
 </project>

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


+ 8
- 0
pom.xml View File

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

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

@@ -0,0 +1,102 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+import java.util.ArrayList;
4
+import java.util.ArrayList;
5
+import java.util.Scanner;
6
+
7
+public class ATM {
8
+
9
+    private ArrayList<Account> accounts = new ArrayList<Account>();
10
+
11
+    private Account selectedAccount;
12
+
13
+    public void add(Account account) {
14
+        accounts.add(account);
15
+    }
16
+
17
+    public double getTotal() {
18
+        double total = 0.0;
19
+        for (Account account: this.accounts) {
20
+            total += account.getBalance();
21
+        }
22
+        return total;
23
+    }
24
+
25
+    public Account getSelectedAccount() {
26
+        return selectedAccount;
27
+    }
28
+
29
+    public void setSelectedAccount(Account selectedAccount) {
30
+        this.selectedAccount = selectedAccount;
31
+    }
32
+
33
+    public void display(){
34
+        StringBuilder sb = new StringBuilder();
35
+
36
+        int counter = 1;
37
+        for (Account account:this.accounts) {
38
+            sb.append(String.format("%5d. %15s %.2f \n", counter, account.getClass().getSimpleName(), account.getBalance()));
39
+            counter++;
40
+        }
41
+        System.out.println(sb.toString());
42
+    }
43
+
44
+    public void run(){
45
+        this.add(new CheckingAccount(2000));
46
+        this.add(new SavingsAccount(1500));
47
+        this.add(new BusinessAccount(3000));
48
+
49
+        String input;
50
+
51
+        while(true){
52
+            if(this.selectedAccount == null){
53
+                this.display();
54
+                input = getInput("Please Select a Account: ");
55
+
56
+                if(input.equalsIgnoreCase("Checkings")){
57
+                    this.selectedAccount = this.accounts.get(0);
58
+                } else if(input.equalsIgnoreCase("Savings")){
59
+                    this.selectedAccount = this.accounts.get(1);
60
+                } else if(input.equalsIgnoreCase("Business")){
61
+                    this.selectedAccount = this.accounts.get(2);
62
+                } if(input.equalsIgnoreCase("Exit")){
63
+                    System.out.println("Thank you for using my ATM");
64
+                    break;
65
+                }
66
+            } else {
67
+                System.out.println("You are selected into your " + this.selectedAccount.getClass().getSimpleName() + "\n");
68
+                System.out.println(this.selectedAccount.getBalance());
69
+                input = getInput("Please Enter Withdraw, Deposit or Check Balance");
70
+
71
+                if(input.equalsIgnoreCase("Withdraw")){
72
+
73
+                    input = getInput("Enter a amount to Withdraw");
74
+                    this.selectedAccount.withdraw(Double.parseDouble(input));
75
+
76
+                } else if(input.equalsIgnoreCase("Deposit")){
77
+
78
+                    input = getInput("Enter a amount to Deposit");
79
+                    this.selectedAccount.deposit(Double.parseDouble(input));
80
+
81
+                } else if(input.equalsIgnoreCase("Check Balance")){
82
+
83
+                    System.out.println(this.selectedAccount.getBalance());
84
+
85
+                } else if(input.equalsIgnoreCase("exit")){
86
+
87
+                    this.selectedAccount = null;
88
+                }
89
+            }
90
+
91
+        }
92
+
93
+    }
94
+
95
+
96
+    public static String getInput(String prompt) {
97
+        System.out.println(prompt);
98
+        Scanner scanner = new Scanner(System.in);
99
+        return scanner.nextLine();
100
+    }
101
+
102
+}

+ 36
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/Account.java View File

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

+ 0
- 7
src/main/java/com/zipcodewilmington/bankaccountlab/BankAccount.java View File

@@ -1,7 +0,0 @@
1
-package com.zipcodewilmington.bankaccountlab;
2
-
3
-/**
4
- * Created by leon on 1/10/18.
5
- */
6
-public class BankAccount {
7
-}

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

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

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

@@ -0,0 +1,9 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class CheckingAccount extends Account {
4
+
5
+    public CheckingAccount(double balance) {
6
+        super( balance );
7
+    }
8
+
9
+}

+ 9
- 2
src/main/java/com/zipcodewilmington/bankaccountlab/MainApplication.java View File

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

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

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

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

@@ -0,0 +1,34 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+import org.junit.Assert;
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+
6
+public class ATMTest {
7
+
8
+    ATM atm;
9
+
10
+    @Before
11
+    public void setUp(){
12
+
13
+        atm = new ATM();
14
+        atm.add(new CheckingAccount(3000));
15
+        atm.add(new SavingsAccount(4000));
16
+        atm.add(new BusinessAccount(5000));
17
+    }
18
+
19
+
20
+    @Test
21
+    public void getTotal(){
22
+        //expected
23
+        double expected = 12000;
24
+
25
+        //actual
26
+        double actual = atm.getTotal();
27
+
28
+        Assert.assertEquals(expected,actual,0);
29
+    }
30
+
31
+
32
+
33
+
34
+}

+ 0
- 7
src/test/java/com/zipcodewilmington/bankaccountlab/BankAccountTest.java View File

@@ -1,7 +0,0 @@
1
-package com.zipcodewilmington.bankaccountlab;
2
-
3
-/**
4
- * Created by leon on 1/10/18.
5
- */
6
-public class BankAccountTest {
7
-}

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

@@ -0,0 +1,71 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+import org.junit.Assert;
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+
6
+public class BusinessAccountTest {
7
+
8
+    BusinessAccount ba;
9
+
10
+
11
+    @Before
12
+    public void setUp(){
13
+
14
+        ba = new BusinessAccount(5000);
15
+
16
+    }
17
+
18
+    @Test
19
+    public void withdrawTest(){
20
+        //when
21
+        ba.withdraw(4999);
22
+
23
+        //expected
24
+        double expected = 1;
25
+
26
+        //actual
27
+        double actual = ba.getBalance();
28
+
29
+        Assert.assertEquals(expected,actual,0);
30
+
31
+    }
32
+
33
+
34
+
35
+    @Test
36
+    public void deposit(){
37
+        //when
38
+        ba.deposit(1000);
39
+
40
+        //expected
41
+        double expected = 6000;
42
+
43
+        //actual
44
+        double actual = ba.getBalance();
45
+
46
+        Assert.assertEquals(expected,actual,0);
47
+    }
48
+
49
+
50
+    @Test
51
+    public void getBalance(){
52
+        //expected
53
+        double expected = 5000;
54
+
55
+        //actual
56
+        double actual = ba.getBalance();
57
+
58
+        Assert.assertEquals(expected,actual,0);
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+    }
67
+
68
+
69
+
70
+
71
+}

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

@@ -0,0 +1,64 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+import org.junit.Assert;
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+
6
+public class CheckingAccountTest {
7
+
8
+
9
+    //CheckingAccount ca = new CheckingAccount(5000);
10
+
11
+
12
+    CheckingAccount ca;
13
+
14
+    @Before
15
+    public void setUp(){
16
+        ca = new CheckingAccount(5000);
17
+    }
18
+
19
+
20
+    @Test
21
+    public void withdrawTest(){
22
+        //when
23
+        ca.withdraw(500);
24
+
25
+        //expected
26
+        double expecetd = 4500;
27
+
28
+        //actual
29
+        double actual = ca.getBalance();
30
+
31
+        Assert.assertEquals(expecetd,actual,0);
32
+    }
33
+
34
+
35
+    @Test
36
+    public void deposit(){
37
+        //when
38
+        ca.deposit(500);
39
+
40
+        //expected
41
+        double expected = 5500;
42
+
43
+        //actual
44
+        double actual = ca.getBalance();
45
+
46
+        Assert.assertEquals(expected,actual,0);
47
+    }
48
+
49
+
50
+    @Test
51
+    public void getBalance(){
52
+        //expected
53
+        double expected = 5000;
54
+
55
+        //actual
56
+        double actual = ca.getBalance();
57
+
58
+        Assert.assertEquals(expected,actual,0);
59
+    }
60
+
61
+
62
+
63
+
64
+}

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

@@ -0,0 +1,61 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+import org.junit.Assert;
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+
6
+public class SavingsAccountTest {
7
+
8
+    SavingsAccount sa;
9
+
10
+
11
+    @Before
12
+    public void setUp(){
13
+        sa = new SavingsAccount(5000);
14
+    }
15
+
16
+
17
+    @Test
18
+    public void withdraw(){
19
+        //when
20
+        sa.withdraw(1000);
21
+
22
+        //expected
23
+        double expected = 4000;
24
+
25
+        //actual
26
+        double actual = sa.getBalance();
27
+
28
+        Assert.assertEquals(expected,actual,0);
29
+    }
30
+
31
+
32
+
33
+    @Test
34
+    public void deposit(){
35
+        //when
36
+        sa.deposit(1000);
37
+
38
+        //expected
39
+        double expected = 6000;
40
+
41
+        //actual
42
+        double actual = sa.getBalance();
43
+
44
+        Assert.assertEquals(expected,actual,0);
45
+    }
46
+
47
+
48
+    @Test
49
+    public void getBalance(){
50
+        //expected
51
+        double expected = 5000;
52
+
53
+        //actual
54
+        double actual = sa.getBalance();
55
+
56
+        Assert.assertEquals(expected,actual,0);
57
+    }
58
+
59
+
60
+
61
+}