#21 el banko

otevřený
theuglyduck chce sloučit 1 revizí z větve theuglyduck/ZCW-Inheritance-AbstractBankAccount:master do větve master

+ 1
- 0
.idea/.name Zobrazit soubor

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

+ 0
- 3
.idea/compiler.xml Zobrazit soubor

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

+ 1
- 115
.idea/misc.xml Zobrazit soubor

@@ -1,43 +1,6 @@
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>
3
+  <component name="ExternalStorageConfigurationManager" enabled="true" />
41 4
   <component name="MavenProjectsManager">
42 5
     <option name="originalFiles">
43 6
       <list>
@@ -45,84 +8,7 @@
45 8
       </list>
46 9
     </option>
47 10
   </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 11
   <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
65 12
     <output url="file://$PROJECT_DIR$/out" />
66 13
   </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 14
 </project>

+ 0
- 8
.idea/modules.xml Zobrazit soubor

@@ -1,8 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<project version="4">
3
-  <component name="ProjectModuleManager">
4
-    <modules>
5
-      <module fileurl="file://$PROJECT_DIR$/bankaccountlab.iml" filepath="$PROJECT_DIR$/bankaccountlab.iml" />
6
-    </modules>
7
-  </component>
8
-</project>

+ 593
- 391
.idea/workspace.xml
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


+ 14
- 0
pom.xml Zobrazit soubor

@@ -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>junit</groupId>
13
+            <artifactId>junit</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>compile</scope>
22
+        </dependency>
23
+    </dependencies>
10 24
 
11 25
 
12 26
 </project>

+ 101
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/ATM.java Zobrazit soubor

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

+ 30
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/Account.java Zobrazit soubor

@@ -0,0 +1,30 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public abstract class Account {
4
+    private double total;
5
+
6
+
7
+    public Account(double total){
8
+        this.total = total;
9
+    }
10
+
11
+    public void deposit(double total){
12
+
13
+        this.total += total;
14
+
15
+    }
16
+
17
+
18
+    public double withdraw(double amount){
19
+        total = total - amount;
20
+
21
+
22
+        return amount;
23
+    }
24
+
25
+
26
+    public double getBalance(){
27
+        return total;
28
+
29
+    }
30
+}

+ 9
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/BusinessAccount.java Zobrazit soubor

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

+ 9
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/CheckingAccount.java Zobrazit soubor

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

+ 9
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/MainApplication.java Zobrazit soubor

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

+ 16
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/SavingAccount.java Zobrazit soubor

@@ -0,0 +1,16 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class SavingAccount extends Account {
4
+
5
+    public SavingAccount(double total){
6
+        super(total);
7
+    }
8
+
9
+    public void deposit() {
10
+
11
+    }
12
+
13
+    public void withdraw() {
14
+
15
+    }
16
+}

+ 31
- 0
src/test/java/com/zipcodewilmington/bankaccountlab/ATMTest.java Zobrazit soubor

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

+ 4
- 0
src/test/java/com/zipcodewilmington/bankaccountlab/AccountTest.java Zobrazit soubor

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

+ 1
- 0
src/test/java/com/zipcodewilmington/bankaccountlab/BankAccountTest.java Zobrazit soubor

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

+ 69
- 0
src/test/java/com/zipcodewilmington/bankaccountlab/BusinessAccountTest.java Zobrazit soubor

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

+ 67
- 0
src/test/java/com/zipcodewilmington/bankaccountlab/CheckingAccountTest.java Zobrazit soubor

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

+ 69
- 0
src/test/java/com/zipcodewilmington/bankaccountlab/SavingAccountTest.java Zobrazit soubor

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