#23 KennethT867 Abstract Bank Account

Отворени
KennethT867 заяви обединяване на 4 ревизии от KennethT867/ZCW-Inheritance-AbstractBankAccount:master във master

+ 13
- 0
.idea/libraries/Maven__junit_junit_4_12.xml Целия файл

@@ -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 Целия файл

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

+ 573
- 362
.idea/workspace.xml
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 8
- 0
pom.xml Целия файл

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

+ 72
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/Account.java Целия файл

@@ -0,0 +1,72 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public abstract class Account {
4
+
5
+    private String name;
6
+    private String address;
7
+    private String email;
8
+    public int pin;
9
+    public double balance;
10
+    protected long accountNumber;
11
+
12
+
13
+    public Account(){
14
+        this.balance = 3333.33;
15
+    }
16
+
17
+
18
+
19
+    public void setName(String name){
20
+        this.name = name;
21
+    }
22
+
23
+    public String getName(){
24
+        System.out.println(name);
25
+        return name;
26
+    }
27
+
28
+
29
+
30
+    public void setAddress(String address){
31
+        this.address = address;
32
+    }
33
+
34
+    public String getAddress(){
35
+        System.out.println(address);
36
+        return address;
37
+    }
38
+
39
+
40
+
41
+    public void setEmail(String email){
42
+        this.email = email;
43
+    }
44
+
45
+    public String getEmail(){
46
+        System.out.println(email);
47
+        return email;
48
+    }
49
+
50
+
51
+
52
+    public void setPin(int pin){
53
+        this.pin = pin;
54
+    }
55
+
56
+    public int getPin(){
57
+        System.out.println(pin);
58
+        return pin;
59
+    }
60
+
61
+
62
+
63
+    public double getBalance(){
64
+        System.out.println(balance);
65
+        return balance;
66
+    }
67
+
68
+    public long getAccountNumber(){
69
+
70
+        return accountNumber;
71
+    }
72
+}

+ 38
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/Atm.java Целия файл

@@ -0,0 +1,38 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class Atm {
4
+
5
+
6
+    private double balance;
7
+    private int pin;
8
+
9
+    public double getBalance(Account account){
10
+        System.out.println(account.getBalance());
11
+        return account.getBalance();
12
+    }
13
+
14
+    public double depositMoney(Account account, double depositing){
15
+        account.balance = account.balance + depositing;
16
+        return this.balance;
17
+    }
18
+
19
+    public double withdrawMoney(Account account, double withdrawing){
20
+        account.balance = account.balance - withdrawing;
21
+        return this.balance;
22
+    }
23
+
24
+    public void changePin(Account account, int newPin){
25
+        account.pin = pin;
26
+    }
27
+
28
+
29
+    /*
30
+    Maybe for later
31
+    public void transferMoney(Account accountToTransferFrom, Account accountToTransferTo, int amountToTransfer){
32
+        accountToTransferFrom.withdraw
33
+    }
34
+
35
+     */
36
+
37
+
38
+}

+ 0
- 7
src/main/java/com/zipcodewilmington/bankaccountlab/BankAccount.java Целия файл

@@ -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 Целия файл

@@ -0,0 +1,7 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class BusinessAccount extends Account{
4
+
5
+    public BusinessAccount(String name, String email, String address, int pin, long accountNumber, double balance) {
6
+    }
7
+}

+ 21
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/CheckingAccount.java Целия файл

@@ -0,0 +1,21 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class CheckingAccount extends Account {
4
+
5
+   // CheckingAccount checkingAccount = new CheckingAccount();
6
+
7
+    public CheckingAccount(){
8
+
9
+    }
10
+
11
+    public CheckingAccount(String name, String email, String address, int pin, long accountNumber, double balance) {
12
+
13
+    }
14
+
15
+    public CheckingAccount(double balance){
16
+        this.balance = balance;
17
+    }
18
+
19
+    public void pay(double amountToPay){
20
+    }
21
+}

+ 177
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/MainApplication.java Целия файл

@@ -1,7 +1,184 @@
1 1
 package com.zipcodewilmington.bankaccountlab;
2 2
 
3
+import com.sun.tools.javac.comp.Check;
4
+import sun.applet.Main;
5
+
6
+import java.util.Scanner;
7
+
3 8
 /**
4 9
  * Created by leon on 1/10/18.
5 10
  */
11
+
6 12
 public class MainApplication {
13
+
14
+    private String name;
15
+    private String email;
16
+    private String address;
17
+    private int pin;
18
+    private long accountNumber;
19
+   // private static String name;
20
+   // private static String email;
21
+   // private static String address;
22
+   // private static int pin;
23
+    private boolean runCommandCenter = true;
24
+    private CheckingAccount checkingAccount;
25
+    private BusinessAccount businessAccount;
26
+    private SavingsAccount savingsAccount;
27
+
28
+
29
+
30
+
31
+    Atm atm = new Atm();
32
+
33
+    public static void main(String[] vv) {
34
+        new MainApplication().commandCenter();
35
+
36
+
37
+        System.out.println("Baller ATM only...");
38
+        MainApplication mainApplication = new MainApplication();
39
+    }
40
+
41
+
42
+    public MainApplication() {
43
+        Scanner scannerr = new Scanner(System.in);
44
+
45
+        System.out.println("Enter your name.");
46
+        name = scannerr.nextLine();
47
+
48
+        System.out.println("Enter your email address.");
49
+        email = scannerr.nextLine();
50
+
51
+        System.out.println("Enter your address.");
52
+        address = scannerr.nextLine();
53
+
54
+        System.out.println("Create a pin number.");
55
+        pin = scannerr.nextInt();
56
+
57
+        this.accountNumber = Math.round(Math.random() * 999999999);
58
+            double balance = 00000.00;
59
+
60
+            createBusinessAccount(this.name, this.email, this.address, this.pin, this.accountNumber, balance);
61
+            createSavingsAccount(this.name, this.email, this.address, this.pin, this.accountNumber, balance);
62
+            createCheckingAccount(this.name, this.email, this.address, this.pin, this.accountNumber, balance);
63
+
64
+        while(runCommandCenter){
65
+            commandCenter();
66
+        }
67
+    }
68
+
69
+    public void commandCenter(){
70
+        Scanner scanner = new Scanner(System.in);
71
+
72
+        System.out.println("Your Checking Account balance is: " + checkingAccount.getBalance() +"\nYour Savings Account Balance is: " +savingsAccount.getBalance()+"\nYour Business Account balance is: "+businessAccount.getBalance());
73
+
74
+
75
+        System.out.println("Choose a command");
76
+        System.out.println("'1' - Get the balance of your Checking Account \n'2' - Get the balance of your Savings Account \n'3' - Get balance of your Business Account\n'4' - Deposit money to your Checking Account\n'5' - Deposit money to your Savings Account\n'6' - Deposit money to your Business Account\n'7' - Withdraw money from your Checking Account\n'8' - Withdraw money from your Savings Account\n'9' - Withdraw money from your Business Account\n'10' - Change the pin of your accounts\n'11' - Turn ATM off\n'12' - Forgot pin\n'13' - Forgot name\n'14' - Forgot email\n'15' - Forgot address\n'16' - Trick Input :)\n'17' - Get Account Number");
77
+        int userInput = scanner.nextInt();
78
+
79
+        switch(userInput){
80
+            case 1:
81
+                System.out.println("Your Checking Account balance is: " + checkingAccount.getBalance());
82
+                break;
83
+
84
+            case 2:
85
+                System.out.println("Your Savings Account balance is: " + savingsAccount.getBalance());
86
+                break;
87
+
88
+            case 3:
89
+                System.out.println("Your Business Account balance is: " + businessAccount.getBalance());
90
+                break;
91
+
92
+            case 4:
93
+                System.out.println("How much money would you like to deposit into your Checking Account?");
94
+                atm.depositMoney(checkingAccount, scanner.nextDouble());
95
+                System.out.println("Money deposited.");
96
+                break;
97
+
98
+            case 5:
99
+                System.out.println("How much money would you like to deposit into your Savings Account?");
100
+                atm.depositMoney(savingsAccount, scanner.nextDouble());
101
+                System.out.println("Money deposited.");
102
+                break;
103
+
104
+            case 6:
105
+                System.out.println("How much money would you like to deposit into your Business Account?");
106
+                atm.depositMoney(businessAccount, scanner.nextDouble());
107
+                System.out.println("Money deposited.");
108
+                break;
109
+
110
+            case 7:
111
+                System.out.println("How much money would you like to withdraw from your Checking Account?");
112
+                atm.withdrawMoney(checkingAccount, scanner.nextDouble());
113
+                System.out.println("Money withdrawn.");
114
+                break;
115
+
116
+            case 8:
117
+                System.out.println("How much money would you like to withdraw from your Savings Account?");
118
+                atm.withdrawMoney(savingsAccount, scanner.nextDouble());
119
+                System.out.println("Money withdrawn.");
120
+                break;
121
+
122
+            case 9:
123
+                System.out.println("How much money would you like to withdraw from your Business Account?");
124
+                atm.withdrawMoney(businessAccount, scanner.nextDouble());
125
+                System.out.println("Money withdrawn");
126
+                break;
127
+
128
+            case 10:
129
+                System.out.println("Enter a new pin number.");
130
+                atm.changePin(businessAccount, scanner.nextInt());
131
+                //might have to change all of the pin numbers individually...
132
+                break;
133
+
134
+            case 11:
135
+                System.out.println("Peace");
136
+                runCommandCenter = false;
137
+                break;
138
+
139
+            case 12:
140
+                System.out.println("Your pin number is " + businessAccount.getPin());
141
+                break;
142
+
143
+            case 13:
144
+                System.out.println("Your name is " + businessAccount.getName());
145
+                break;
146
+
147
+            case 14:
148
+                System.out.println("Your email address is " + businessAccount.getEmail());
149
+                break;
150
+
151
+            case 15:
152
+                System.out.println("Your address is " + businessAccount.getAddress());
153
+
154
+            case 17:
155
+                System.out.println("Your account number is " + businessAccount.getAccountNumber());
156
+        }
157
+
158
+    }
159
+
160
+
161
+
162
+
163
+
164
+    public CheckingAccount createCheckingAccount(String name, String email, String address, int pin, long accountNumber, double balance){
165
+        CheckingAccount checkingAccount = new CheckingAccount(name, email, address, pin, accountNumber, balance);
166
+        this.checkingAccount = checkingAccount;
167
+        return this.checkingAccount;
168
+
169
+    }
170
+
171
+    public BusinessAccount createBusinessAccount(String name, String email, String address, int pin, long accountNumber, double balance){
172
+        BusinessAccount businessAccount = new BusinessAccount(name, email, address, pin, accountNumber, balance);
173
+        this.businessAccount = businessAccount;
174
+        return this.businessAccount;
175
+
176
+    }
177
+
178
+    public SavingsAccount createSavingsAccount(String name, String email, String address, int pin, long accountNumber, double balance){
179
+        SavingsAccount savingsAccount = new SavingsAccount(name, email, address, pin, accountNumber, balance);
180
+        this.savingsAccount = savingsAccount;
181
+        return this.savingsAccount;
182
+
183
+    }
7 184
 }

+ 7
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/SavingsAccount.java Целия файл

@@ -0,0 +1,7 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class SavingsAccount extends Account {
4
+
5
+    public SavingsAccount(String name, String email, String address, int pin, long accountNumber, double balance) {
6
+    }
7
+}

+ 0
- 7
src/test/java/com/zipcodewilmington/bankaccountlab/BankAccountTest.java Целия файл

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

+ 81
- 0
src/test/java/com/zipcodewilmington/bankaccountlab/CheckingAccountTest.java Целия файл

@@ -0,0 +1,81 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+import com.sun.tools.javac.comp.Check;
4
+import org.junit.Assert;
5
+import org.junit.Test;
6
+
7
+public class CheckingAccountTest {
8
+
9
+
10
+    @Test
11
+    public void test_Get_Set_Name() {
12
+        CheckingAccount checkingAccount = new CheckingAccount();
13
+
14
+        checkingAccount.setName("Kenneth");
15
+        String expected = "Kenneth";
16
+        String actual = checkingAccount.getName();
17
+        Assert.assertEquals(expected, actual);
18
+    }
19
+
20
+    @Test
21
+    public void test_Get_Set_Address() {
22
+        CheckingAccount checkingAccount = new CheckingAccount();
23
+
24
+        checkingAccount.setAddress("867 Anton Lane");
25
+        String expected = "867 Anton Lane";
26
+        String actual = checkingAccount.getAddress();
27
+        Assert.assertEquals(expected, actual);
28
+    }
29
+
30
+    @Test
31
+    public void test_Get_Set_Email() {
32
+        CheckingAccount checkingAccount = new CheckingAccount();
33
+
34
+        checkingAccount.setEmail("peace_459@live.com");
35
+        String expected = "peace_459@live.com";
36
+        String actual = checkingAccount.getEmail();
37
+        Assert.assertEquals(expected, actual);
38
+    }
39
+
40
+    @Test
41
+    public void test_Get_Set_Pin() {
42
+        CheckingAccount checkingAccount = new CheckingAccount();
43
+
44
+        checkingAccount.setPin(949428);
45
+        int expected = 949428;
46
+        int actual = checkingAccount.getPin();
47
+        Assert.assertEquals(expected, actual);
48
+    }
49
+
50
+    @Test
51
+    public void test_Get_Balance() {
52
+        CheckingAccount checkingAccount = new CheckingAccount();
53
+
54
+        double actual = checkingAccount.getBalance();
55
+        double expected = 3333.33;
56
+        Assert.assertTrue(expected == actual);
57
+    }
58
+
59
+    @Test
60
+    public void testPay_WriteCheck(){
61
+        CheckingAccount checkingAccount = new CheckingAccount(555.55);
62
+
63
+        double amountToPay = 13.82;
64
+        checkingAccount.pay(amountToPay);
65
+
66
+        Assert.assertEquals(541.73 , 555.55 - amountToPay, 541.73);
67
+    }
68
+
69
+    @Test
70
+    public void testGetAccountNumber(){
71
+        CheckingAccount checkingAccount = new CheckingAccount();
72
+
73
+        MainApplication mainApplication = new MainApplication();
74
+
75
+        long actual = checkingAccount.getAccountNumber();
76
+
77
+        Assert.assertTrue(actual > 0 && actual < 999999999);
78
+    }
79
+
80
+
81
+}

+ 13
- 0
src/test/java/com/zipcodewilmington/bankaccountlab/TestAtm.java Целия файл

@@ -0,0 +1,13 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+import org.junit.Test;
4
+
5
+public class TestAtm {
6
+
7
+    @Test
8
+    public void testGetBalance(){
9
+
10
+
11
+
12
+    }
13
+}