#1 laurenstewartgreen

Open
laurengreen wants to merge 11 commits from laurengreen/CashMachine:master into master

+ 24
- 30
README.TXT View File

@@ -4,8 +4,8 @@
4 4
 
5 5
 A simple cash account <-> bank system implementation (very loosely modelled!)
6 6
 
7
-This project uses JavaFX for the user interface toolkit. JavaFX is a software platform for creating 
8
-and delivering desktop applications, as well as rich Internet applications (RIAs) 
7
+This project uses JavaFX for the user interface toolkit. JavaFX is a software platform for creating
8
+and delivering desktop applications, as well as rich Internet applications (RIAs)
9 9
 that can run across a wide variety of devices. It is part of the standard Java distribution.
10 10
 
11 11
 Welcome to your first App. "ZipCloudBank", a local Wilmington fintech startup, has a minimally
@@ -16,24 +16,24 @@ The Board of Directors of ZipCloudBank have empowered me to let you take a crack
16 16
 and improving their app over this weekend. Impressed that you are a ZipCode student, they are
17 17
 expecting great things. Don't panic: we think you can do this.
18 18
 
19
-The point of this lab is to read thru some existing code, in this case, a program/app that 
19
+The point of this lab is to read thru some existing code, in this case, a program/app that
20 20
 launches a window on your computer and lets you play with a couple of "banking accounts".
21 21
 You should run the app, learn how to use it, so you understand what it does. It is not,
22 22
 shall we say, user-friendly. So you may find what you have to do to make it work somewhat
23
-awkward. 
23
+awkward.
24 24
 
25
-Then, you should read thru the code repository seeing how the code actually implements the things you 
25
+Then, you should read thru the code repository seeing how the code actually implements the things you
26 26
 see when you run the code. Find the "main" routine, which is where the app starts up. Trace from there
27 27
 to see what code gets called where and when. Trace how the operations of the code work.
28 28
 
29 29
 Finally, you are to add some new functionality to the app, to make it "more useful, powerful &
30
-more rewarding for the user". 
30
+more rewarding for the user".
31 31
 Your effort will be met with promotions, parades, and stock options. (no, just kidding).
32 32
 
33 33
 Lab Brief
34 34
 =========
35 35
 
36
-Notice the structure of the current project before you start. Read thru the 
36
+Notice the structure of the current project before you start. Read thru the
37 37
 code up here on git.zipcode.rocks.
38 38
 Read thru the code. READ THRU THE CODE.
39 39
 READ THRU THE CODE.
@@ -63,23 +63,23 @@ Notice when reading the code...
63 63
 Things to Change for the Lab
64 64
 ============================
65 65
 
66
-FIRST, fork this repo into your own account. 
66
+FIRST, fork this repo into your own account.
67 67
        =====================================
68 68
 
69
-     After getting each of these items completed, 
70
-     be sure to do a 'git commit' to save you work. 
69
+     After getting each of these items completed,
70
+     be sure to do a 'git commit' to save you work.
71 71
      Learn your git.
72
-     Never Lose Code. 
72
+     Never Lose Code.
73 73
      NEVER LOSE CODE. EVER. :-)
74 74
 
75 75
 How about making a new git branch, named "dev" from the master branch for you to do all
76 76
 your work in?? (what great idea!)
77 77
 
78
-NOW, maybe you're ready to start making changes. 
78
+NOW, maybe you're ready to start making changes.
79 79
 
80 80
 
81 81
 
82
-* Add more accounts to the default constructor of the Bank class.
82
+X  * Add more accounts to the default constructor of the Bank class.
83 83
 * When you overdraft an account, print an alert message to the areaInfo object on the window.
84 84
 
85 85
 Additional things to add
@@ -89,24 +89,18 @@ You need not do these things in this order. Do as many as you can. When you fini
89 89
 make sure the project runs. (Else the Board... well, disappointment lies that direction.)
90 90
      ---------------------
91 91
 
92
-* Make the account display more user friendly
93
-  * add a Form layout that has separate TextFields for each piece of account info. 
94
-  * You'll probably find a layout that lets you do this, a little like the FlowPane.
95
-  * Make the login stuff more clear
96
-  * Disable the three buttons that operate on an account until a login happens 
97
-  * and then enable them. add another TextField for the amount entries. 
98
-  * Make it different from the TextField where you set the account ID.
92
+Make the account display more user friendly
93
+X   * Add a Form layout that has separate TextFields for each piece of account info. You'll probably find a layout that lets you do this, a little like the FlowPane.
94
+X  * Make the login stuff more clear
95
+X  * Disable the three buttons that operate on an account until a login happens and then enable them.
96
+X  * Add another TextField for the amount entries. Make it different from the TextField where you set the account ID.
97
+X  * Enable the amount entries to be floating point numbers instead of just integers when doing deposits and withdrawals.
98
+X   * Add a menu with a list of accounts in it and the menu action switched to that account. You may find that JavaFX already has such a thing.
99 99
 
100
-* Enable the amount entries to be floating point numbers instead of 
101
-  just integers when doing deposits and withdrawals.
102
-
103
-* Add a menu with a list of accounts in it and the menu action switched 
104
-  to that account. You may find that JavaFX already has such a thing.
105
-
106
-**** Add a New Account Window(!) that takes in the info required thru 
107
-     TextFields and creates the correct objects so that is can be changed 
100
+**** Add a New Account Window(!) that takes in the info required thru
101
+     TextFields and creates the correct objects so that is can be changed
108 102
      like the pre-wired accounts.
109 103
 
110
-NB: When googling for information on how to do all this, 
111
-be sure you start every query with "javafx " and your other search terms. 
104
+NB: When googling for information on how to do all this,
105
+be sure you start every query with "javafx " and your other search terms.
112 106
 That will limit the results to things that probably are closer to what you need.

+ 54
- 3
src/main/java/rocks/zipcode/atm/CashMachine.java View File

@@ -1,8 +1,13 @@
1 1
 package rocks.zipcode.atm;
2 2
 
3
+import com.sun.javafx.binding.StringFormatter;
4
+import javafx.collections.FXCollections;
5
+import javafx.collections.ObservableList;
3 6
 import rocks.zipcode.atm.bank.AccountData;
4 7
 import rocks.zipcode.atm.bank.Bank;
5 8
 
9
+import java.util.ArrayList;
10
+import java.util.Observable;
6 11
 import java.util.function.Consumer;
7 12
 import java.util.function.Supplier;
8 13
 
@@ -15,13 +20,55 @@ public class CashMachine {
15 20
     private AccountData accountData = null;
16 21
 
17 22
     public CashMachine(Bank bank) {
23
+
18 24
         this.bank = bank;
25
+
26
+
27
+    }
28
+
29
+    public int getId() {
30
+        return accountData.getId();
31
+    }
32
+
33
+    public String getName() {
34
+        return accountData.getName();
35
+    }
36
+
37
+    public String getEmail() {
38
+        return accountData.getEmail();
39
+    }
40
+
41
+
42
+    public Float getBalance() {
43
+
44
+        return accountData.getBalance();
19 45
     }
20 46
 
21 47
     private Consumer<AccountData> update = data -> {
22 48
         accountData = data;
23 49
     };
24 50
 
51
+    public void resetPassword(int accountNumber, String newPassword) {
52
+        bank.resetPassword(accountNumber, newPassword);
53
+    }
54
+
55
+    public ObservableList<Integer> getIdList() {
56
+
57
+        ObservableList<Integer> idList = FXCollections.observableArrayList(bank.getIdList());
58
+
59
+        return idList;
60
+    }
61
+
62
+    public String message(String message) {
63
+        return message;
64
+    }
65
+
66
+    public boolean checkPassword(int accountNumber, String password) {
67
+
68
+        password.toLowerCase();
69
+        return bank.getPassword(accountNumber).equals(password);
70
+    }
71
+
25 72
     public void login(int id) {
26 73
         tryCall(
27 74
                 () -> bank.getAccountById(id),
@@ -29,7 +76,7 @@ public class CashMachine {
29 76
         );
30 77
     }
31 78
 
32
-    public void deposit(int amount) {
79
+    public void deposit(float amount) {
33 80
         if (accountData != null) {
34 81
             tryCall(
35 82
                     () -> bank.deposit(accountData, amount),
@@ -38,15 +85,17 @@ public class CashMachine {
38 85
         }
39 86
     }
40 87
 
41
-    public void withdraw(int amount) {
88
+    public void withdraw(float amount) {
42 89
         if (accountData != null) {
43 90
             tryCall(
44 91
                     () -> bank.withdraw(accountData, amount),
45 92
                     update
46 93
             );
94
+
47 95
         }
48 96
     }
49 97
 
98
+
50 99
     public void exit() {
51 100
         if (accountData != null) {
52 101
             accountData = null;
@@ -55,9 +104,10 @@ public class CashMachine {
55 104
 
56 105
     @Override
57 106
     public String toString() {
58
-        return accountData != null ? accountData.toString() : "Try account 1000 or 2000 and click submit.";
107
+        return accountData != null ? accountData.toString() : "Incorrect account number. \nTry again or click 'Forgot Account Number'";
59 108
     }
60 109
 
110
+
61 111
     private <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {
62 112
         try {
63 113
             ActionResult<T> result = action.get();
@@ -72,4 +122,5 @@ public class CashMachine {
72 122
             System.out.println("Error: " + e.getMessage());
73 123
         }
74 124
     }
125
+
75 126
 }

+ 222
- 22
src/main/java/rocks/zipcode/atm/CashMachineApp.java View File

@@ -1,78 +1,278 @@
1 1
 package rocks.zipcode.atm;
2 2
 
3
+import javafx.geometry.Pos;
4
+import javafx.scene.control.*;
5
+import javafx.scene.control.Button;
6
+import javafx.scene.control.Label;
7
+import javafx.scene.control.TextArea;
8
+import javafx.scene.control.TextField;
9
+import javafx.scene.image.ImageViewBuilder;
10
+import javafx.scene.layout.HBox;
11
+import javafx.scene.text.TextAlignment;
12
+import javafx.scene.text.TextFlow;
13
+import javafx.stage.StageStyle;
3 14
 import rocks.zipcode.atm.bank.Bank;
4 15
 import javafx.application.Application;
5 16
 import javafx.scene.Parent;
6 17
 import javafx.scene.Scene;
7
-import javafx.scene.control.Button;
8
-import javafx.scene.control.TextArea;
9
-import javafx.scene.control.TextField;
10 18
 import javafx.scene.layout.VBox;
11 19
 import javafx.stage.Stage;
12 20
 import javafx.scene.layout.FlowPane;
13 21
 
22
+
23
+import javax.swing.*;
24
+import javax.swing.text.html.ImageView;
25
+import javax.xml.soap.Text;
26
+import java.awt.*;
27
+import java.awt.Image;
28
+import java.io.FileInputStream;
29
+import java.util.HashMap;
30
+
14 31
 /**
15 32
  * @author ZipCodeWilmington
16 33
  */
17 34
 public class CashMachineApp extends Application {
18 35
 
19 36
     private TextField field = new TextField();
37
+    private TextField field2 = new TextField();
20 38
     private CashMachine cashMachine = new CashMachine(new Bank());
39
+    private ComboBox accountNumbers = new ComboBox(cashMachine.getIdList());
21 40
 
22 41
     private Parent createContent() {
23 42
         VBox vbox = new VBox(10);
24
-        vbox.setPrefSize(600, 600);
43
+        vbox.setPrefSize(600, 820);
44
+        vbox.setStyle("-fx-background-color: lightslategray; -fx-padding: 20; -fx-font-size: 20;");
45
+
46
+        Label header = new Label("Welcome to ZipCloud Bank");
47
+        header.setStyle("-fx-text-fill: turquoise; -fx-font-size: 42; -fx-font-family: Charter; -fx-border-radius: 10; -fx-label-padding: 8; -fx-border-width: 4; -fx-border-color: greenyellow;");
48
+
49
+
50
+
51
+        TextField areaAccountId = new TextField();
52
+        areaAccountId.setStyle("-fx-background-color: lightsteelblue;");
53
+        areaAccountId.setManaged(false);
54
+        areaAccountId.setEditable(false);
55
+
56
+        Label accountId = new Label("Account ID:");
57
+        accountId.setManaged(false);
58
+        accountId.setStyle("-fx-text-fill: white;");
59
+
60
+       // HBox accountIdInfo = new HBox(5);
61
+        //accountIdInfo.getChildren().addAll(accountId, areaAccountId);
25 62
 
26
-        TextArea areaInfo = new TextArea();
63
+        TextField areaAccountName = new TextField();
64
+        areaAccountName.setManaged(false);
65
+        areaAccountName.setStyle("-fx-background-color: lightsteelblue;");
66
+        areaAccountName.setEditable(false);
27 67
 
28
-        Button btnSubmit = new Button("Set Account ID");
68
+        Label accountName = new Label("Account Holder:");
69
+        accountName.setStyle("-fx-text-fill: white;");
70
+        accountName.setManaged(false);
71
+
72
+        //HBox nameInfo = new HBox(5);
73
+        //nameInfo.getChildren().addAll(accountName, areaAccountName);
74
+
75
+        TextField areaAccountEmail = new TextField();
76
+        areaAccountEmail.setManaged(false);
77
+        areaAccountEmail.setStyle("-fx-background-color: lightsteelblue;");
78
+        areaAccountEmail.setEditable(false);
79
+
80
+        Label accountEmail = new Label("Email:");
81
+        accountEmail.setStyle("-fx-text-fill: white;");
82
+        accountEmail.setManaged(false);
83
+
84
+        //HBox accountEmailInfo = new HBox(5);
85
+        //accountEmailInfo.getChildren().addAll(accountEmail, areaAccountEmail);
86
+
87
+        TextField areaAccountAmount = new TextField();
88
+        areaAccountAmount.setManaged(false);
89
+        areaAccountAmount.setStyle("-fx-background-color: mediumturquoise;");
90
+        areaAccountAmount.setEditable(false);
91
+
92
+        Label accountBalance = new Label("Balance:");
93
+        accountBalance.setStyle("-fx-text-fill: greenyellow;");
94
+        accountBalance.setManaged(false);
95
+
96
+        /*
97
+        HBox accountBalanceInfo = new HBox(5);
98
+        accountBalanceInfo.getChildren().addAll(accountBalance, areaAccountAmount);
99
+
100
+        accountIdInfo.setPrefSize(100, 100);
101
+        accountIdInfo.setStyle("-fx-background-color: mediumaquamarine; -fx-padding: 20; -fx-font-size: 20;");
102
+        */
103
+
104
+        field2.setManaged(false);
105
+
106
+        Label fieldLabel2 = new Label("Amount:");
107
+        fieldLabel2.setManaged(false);
108
+        fieldLabel2.setStyle("-fx-text-fill: greenyellow;");
109
+        Label fieldLabel = new Label("Select Your Account Number:");
110
+        fieldLabel.setStyle("-fx-text-fill: greenyellow;");
111
+
112
+        field.setStyle("-fx-background-color: lightgrey;");
113
+        field2.setStyle("-fx-background-color: lightgrey;");
114
+        Label passwordLabel = new Label("Password:");
115
+        passwordLabel.setStyle("-fx-text-fill: greenyellow;");
116
+
117
+
118
+        //Make Button Do something.
119
+        Button btnNewAccount = new Button("Setup New Account");
120
+        btnNewAccount.setDisable(true);
121
+       /*
29 122
         btnSubmit.setOnAction(e -> {
30
-            int id = Integer.parseInt(field.getText());
31
-            cashMachine.login(id);
32 123
 
33
-            areaInfo.setText(cashMachine.toString());
34 124
         });
125
+*/
35 126
 
36 127
         Button btnDeposit = new Button("Deposit");
128
+        btnDeposit.setManaged(false);
37 129
         btnDeposit.setOnAction(e -> {
38
-            int amount = Integer.parseInt(field.getText());
130
+            float amount = Float.parseFloat(field2.getText());
39 131
             cashMachine.deposit(amount);
40 132
 
41
-            areaInfo.setText(cashMachine.toString());
133
+            areaAccountAmount.setText(Float.toString(cashMachine.getBalance()));
42 134
         });
43 135
 
136
+
44 137
         Button btnWithdraw = new Button("Withdraw");
138
+        btnWithdraw.setManaged(false);
45 139
         btnWithdraw.setOnAction(e -> {
46
-            int amount = Integer.parseInt(field.getText());
140
+            float amount = Float.parseFloat(field2.getText());
47 141
             cashMachine.withdraw(amount);
142
+            areaAccountAmount.setText(Float.toString(cashMachine.getBalance()));
143
+        });
48 144
 
49
-            areaInfo.setText(cashMachine.toString());
145
+        Button btnResetPassword = new Button("Reset Password");
146
+        btnResetPassword.setManaged(false);
147
+        btnResetPassword.setOnAction(e -> {
148
+            int id = Integer.parseInt(accountNumbers.getValue().toString());
149
+            String password = field.getText();
150
+            cashMachine.resetPassword(id, password);
151
+            passwordLabel.setText(cashMachine.message("Password Reset."));
50 152
         });
51 153
 
52
-        Button btnExit = new Button("Exit");
154
+        Button btnExit = new Button("Log Out");
155
+        btnExit.setManaged(false);
53 156
         btnExit.setOnAction(e -> {
54 157
             cashMachine.exit();
158
+            field.clear();
159
+            field2.clear();
160
+            areaAccountAmount.clear();
161
+            areaAccountEmail.clear();
162
+            areaAccountId.clear();
163
+            areaAccountName.clear();
164
+            passwordLabel.setText("Password:");
165
+
166
+
167
+            field2.setVisible(false);
168
+            fieldLabel2.setVisible(false);
169
+            btnDeposit.setVisible(false);
170
+            btnWithdraw.setVisible(false);
171
+            btnExit.setVisible(false);
172
+            btnResetPassword.setVisible(false);
173
+
174
+            areaAccountAmount.setVisible(false);
175
+            areaAccountEmail.setVisible(false);
176
+            areaAccountId.setVisible(false);
177
+            areaAccountName.setVisible(false);
178
+
179
+            accountBalance.setVisible(false);
180
+            accountEmail.setVisible(false);
181
+            accountId.setVisible(false);
182
+            accountName.setVisible(false);
183
+        });
184
+
185
+        Button btnSubmit = new Button("Enter");
186
+        btnSubmit.setOnAction(e -> {
187
+            int id = Integer.parseInt(accountNumbers.getValue().toString());
188
+            String passwordInput = field.getText();
189
+            if(cashMachine.checkPassword(id, passwordInput)) {
190
+                cashMachine.login(id);
191
+                areaAccountAmount.setText(Float.toString(cashMachine.getBalance()));
192
+                areaAccountEmail.setText(cashMachine.getEmail());
193
+                areaAccountId.setText(Integer.toString(cashMachine.getId()));
194
+                areaAccountName.setText(cashMachine.getName());
195
+                areaAccountAmount.setManaged(true);
196
+                areaAccountEmail.setManaged(true);
197
+                areaAccountId.setManaged(true);
198
+                areaAccountName.setManaged(true);
199
+                accountId.setManaged(true);
200
+                accountName.setManaged(true);
201
+                accountEmail.setManaged(true);
202
+                accountBalance.setManaged(true);
203
+                passwordLabel.setText("New Password:");
204
+                btnDeposit.setManaged(true);
205
+                btnWithdraw.setManaged(true);
206
+                btnExit.setManaged(true);
207
+                btnResetPassword.setManaged(true);
208
+                accountId.setManaged(true);
209
+                field2.setManaged(true);
210
+                fieldLabel2.setManaged(true);
211
+
212
+                field2.setVisible(true);
213
+                fieldLabel2.setVisible(true);
214
+                btnDeposit.setVisible(true);
215
+                btnWithdraw.setVisible(true);
216
+                btnExit.setVisible(true);
217
+                btnResetPassword.setVisible(true);
218
+
219
+                areaAccountAmount.setVisible(true);
220
+                areaAccountEmail.setVisible(true);
221
+                areaAccountId.setVisible(true);
222
+                areaAccountName.setVisible(true);
223
+
224
+                accountBalance.setVisible(true);
225
+                accountEmail.setVisible(true);
226
+                accountId.setVisible(true);
227
+                accountName.setVisible(true);
55 228
 
56
-            areaInfo.setText(cashMachine.toString());
229
+            } else {
230
+                passwordLabel.setText(cashMachine.message("Incorrect Password.  Try Again."));
231
+            }
57 232
         });
58 233
 
234
+
235
+
236
+        /*
237
+        String path = "https://drive.google.com/file/d/1PR_cLhzJ9IFcnWF46QSX_WEcnFT-uI0Q/view?usp=sharing";
238
+
239
+        Image image = new Image(path);
240
+*/
241
+
59 242
         FlowPane flowpane = new FlowPane();
60 243
 
61 244
         flowpane.getChildren().add(btnSubmit);
62
-        flowpane.getChildren().add(btnDeposit);
63
-        flowpane.getChildren().add(btnWithdraw);
64
-        flowpane.getChildren().add(btnExit);
65
-        vbox.getChildren().addAll(field, flowpane, areaInfo);
245
+        flowpane.getChildren().add(btnResetPassword);
246
+        flowpane.getChildren().add(btnNewAccount);
247
+
248
+        FlowPane flowpane2 = new FlowPane();
249
+
250
+        flowpane2.getChildren().add(btnDeposit);
251
+        flowpane2.getChildren().add(btnWithdraw);
252
+        flowpane2.getChildren().add(btnExit);
253
+
254
+        vbox.getChildren().addAll(header, fieldLabel, accountNumbers, passwordLabel, field, flowpane, fieldLabel2, field2, flowpane2, accountId, areaAccountId, accountName, areaAccountName, accountEmail, areaAccountEmail, accountBalance, areaAccountAmount);
255
+
256
+
257
+
66 258
         return vbox;
259
+
260
+
67 261
     }
68 262
 
69 263
     @Override
70
-    public void start(Stage stage) throws Exception {
71
-        stage.setScene(new Scene(createContent()));
72
-        stage.show();
264
+    public void start(Stage primarystage) throws Exception {
265
+        primarystage.setTitle("ZipCloud Bank");
266
+        primarystage.setScene(new Scene(createContent()));
267
+        primarystage.show();
268
+
73 269
     }
74 270
 
75 271
     public static void main(String[] args) {
272
+
76 273
         launch(args);
274
+
77 275
     }
276
+
277
+
78 278
 }

+ 5
- 5
src/main/java/rocks/zipcode/atm/bank/Account.java View File

@@ -15,11 +15,11 @@ public abstract class Account {
15 15
         return accountData;
16 16
     }
17 17
 
18
-    public void deposit(int amount) {
18
+    public void deposit(float amount) {
19 19
         updateBalance(getBalance() + amount);
20 20
     }
21 21
 
22
-    public boolean withdraw(int amount) {
22
+    public boolean withdraw(float amount) {
23 23
         if (canWithdraw(amount)) {
24 24
             updateBalance(getBalance() - amount);
25 25
             return true;
@@ -28,15 +28,15 @@ public abstract class Account {
28 28
         }
29 29
     }
30 30
 
31
-    protected boolean canWithdraw(int amount) {
31
+    protected boolean canWithdraw(float amount) {
32 32
         return getBalance() >= amount;
33 33
     }
34 34
 
35
-    public int getBalance() {
35
+    public float getBalance() {
36 36
         return accountData.getBalance();
37 37
     }
38 38
 
39
-    private void updateBalance(int newBalance) {
39
+    private void updateBalance(float newBalance) {
40 40
         accountData = new AccountData(accountData.getId(), accountData.getName(), accountData.getEmail(),
41 41
                 newBalance);
42 42
     }

+ 5
- 5
src/main/java/rocks/zipcode/atm/bank/AccountData.java View File

@@ -9,9 +9,9 @@ public final class AccountData {
9 9
     private final String name;
10 10
     private final String email;
11 11
 
12
-    private final int balance;
12
+    private final float balance;
13 13
 
14
-    AccountData(int id, String name, String email, int balance) {
14
+    AccountData(int id, String name, String email, float balance) {
15 15
         this.id = id;
16 16
         this.name = name;
17 17
         this.email = email;
@@ -30,15 +30,15 @@ public final class AccountData {
30 30
         return email;
31 31
     }
32 32
 
33
-    public int getBalance() {
33
+    public float getBalance() {
34 34
         return balance;
35 35
     }
36 36
 
37 37
     @Override
38 38
     public String toString() {
39
-        return "Account id: " + id + '\n' +
39
+        return "Account ID: " + id + '\n' +
40 40
                 "Name: " + name + '\n' +
41 41
                 "Email: " + email + '\n' +
42
-                "Balance: " + balance;
42
+                "Balance: $" + String.format("%,.2f", balance);
43 43
     }
44 44
 }

+ 114
- 6
src/main/java/rocks/zipcode/atm/bank/Bank.java View File

@@ -1,7 +1,11 @@
1 1
 package rocks.zipcode.atm.bank;
2 2
 
3
+import javafx.collections.FXCollections;
4
+import javafx.collections.ObservableList;
3 5
 import rocks.zipcode.atm.ActionResult;
4 6
 
7
+import java.awt.*;
8
+import java.util.ArrayList;
5 9
 import java.util.HashMap;
6 10
 import java.util.Map;
7 11
 
@@ -11,15 +15,118 @@ import java.util.Map;
11 15
 public class Bank {
12 16
 
13 17
     private Map<Integer, Account> accounts = new HashMap<>();
18
+    private Map<Integer, String> passwords = new HashMap<>();
19
+    //private static int nextId = 1000;
20
+
21
+    /* Add options for user to create an account and have a number issued to them. */
14 22
 
15 23
     public Bank() {
16 24
         accounts.put(1000, new BasicAccount(new AccountData(
17
-                1000, "Example 1", "example1@gmail.com", 500
25
+                1000, "Nick Foles", "LIImvp@gmail.com", 500
26
+        )));
27
+
28
+        passwords.put(1000, "password");
29
+
30
+        accounts.put(1100, new BasicAccount(new AccountData(
31
+                1100, "Dan Green", "dgreen@gmail.com", 100000
32
+        )));
33
+
34
+        passwords.put(1100, "password");
35
+
36
+        accounts.put(1200, new BasicAccount(new AccountData(
37
+                1200, "Billy Madison", "back2school@gmail.com", 500
38
+        )));
39
+
40
+        passwords.put(1200, "password");
41
+
42
+        accounts.put(1300, new BasicAccount(new AccountData(
43
+                1300, "Chase Utley", "grandpa@gmail.com", 2008
44
+        )));
45
+
46
+        passwords.put(1300, "password");
47
+
48
+        accounts.put(1400, new PremiumAccount(new AccountData(
49
+                1400, "Elle Woods", "pink@gmail.com", 20
18 50
         )));
19 51
 
52
+        passwords.put(1400, "password");
53
+
54
+        accounts.put(1500, new PremiumAccount(new AccountData(
55
+                1500, "Harry Potter", "seeker4life@wizmail.com", 200
56
+        )));
57
+
58
+        passwords.put(1500, "password");
59
+
60
+        accounts.put(1600, new BasicAccount(new AccountData(
61
+                1600, "Hermione Granger", "librarylover@gmail.com", 950
62
+        )));
63
+
64
+        passwords.put(1600, "password");
65
+
66
+        accounts.put(1700, new BasicAccount(new AccountData(
67
+                1700, "Hayden Stewart", "hstew@gmail.com", 100
68
+        )));
69
+
70
+        passwords.put(1700, "password");
71
+
72
+        accounts.put(1800, new BasicAccount(new AccountData(
73
+                1800, "Jack Traven", "speed@gmail.com", 50
74
+        )));
75
+
76
+        passwords.put(1800, "password");
77
+
78
+        accounts.put(1900, new BasicAccount(new AccountData(
79
+                1900, "Jimmy Fallon", "jimmy@nbc.com", 1000
80
+        )));
81
+
82
+        passwords.put(1900, "password");
83
+
20 84
         accounts.put(2000, new PremiumAccount(new AccountData(
21
-                2000, "Example 2", "example2@gmail.com", 200
85
+                2000, "Frankie Smith", "frank@gmail.com", 2040
22 86
         )));
87
+
88
+        passwords.put(2000, "password");
89
+
90
+        accounts.put(2100, new PremiumAccount(new AccountData(
91
+                2100, "Ron Weasley", "ron@wizmail.com", 2003
92
+        )));
93
+
94
+        passwords.put(2100, "password");
95
+    }
96
+
97
+/*How to use this???
98
+    public Bank(String name, String email, int initialBalance, boolean typeOfAccount) {
99
+        nextId++;
100
+        if (!typeOfAccount) {
101
+        accounts.put(nextId, new BasicAccount(new AccountData(
102
+                nextId, name, email, initialBalance
103
+        ))); } else {
104
+            accounts.put(nextId, new PremiumAccount(new AccountData(
105
+                    nextId, name, email, initialBalance
106
+            )));
107
+        }
108
+
109
+    }
110
+
111
+*/
112
+
113
+    public String getPassword(int accountNumber) {
114
+        return passwords.get(accountNumber);
115
+    }
116
+
117
+    public void resetPassword(int accountNumber, String newPassword) {
118
+        passwords.put(accountNumber, newPassword);
119
+    }
120
+
121
+    public ObservableList<Integer> getIdList() {
122
+
123
+        ObservableList<Integer> idList = FXCollections.observableArrayList();
124
+
125
+        for (Integer key: accounts.keySet()) {
126
+
127
+            idList.add(key);
128
+        }
129
+            return idList;
23 130
     }
24 131
 
25 132
     public ActionResult<AccountData> getAccountById(int id) {
@@ -28,25 +135,26 @@ public class Bank {
28 135
         if (account != null) {
29 136
             return ActionResult.success(account.getAccountData());
30 137
         } else {
31
-            return ActionResult.fail("No account with id: " + id + "\nTry account 1000 or 2000");
138
+            return ActionResult.fail("No account with id: " + id);
32 139
         }
33 140
     }
34 141
 
35
-    public ActionResult<AccountData> deposit(AccountData accountData, int amount) {
142
+    public ActionResult<AccountData> deposit(AccountData accountData, float amount) {
36 143
         Account account = accounts.get(accountData.getId());
37 144
         account.deposit(amount);
38 145
 
39 146
         return ActionResult.success(account.getAccountData());
40 147
     }
41 148
 
42
-    public ActionResult<AccountData> withdraw(AccountData accountData, int amount) {
149
+    public ActionResult<AccountData> withdraw(AccountData accountData, float amount) {
43 150
         Account account = accounts.get(accountData.getId());
44 151
         boolean ok = account.withdraw(amount);
45
-
46 152
         if (ok) {
47 153
             return ActionResult.success(account.getAccountData());
48 154
         } else {
49 155
             return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
50 156
         }
51 157
     }
158
+
159
+
52 160
 }

+ 1
- 1
src/main/java/rocks/zipcode/atm/bank/PremiumAccount.java View File

@@ -12,7 +12,7 @@ public class PremiumAccount extends Account {
12 12
     }
13 13
 
14 14
     @Override
15
-    protected boolean canWithdraw(int amount) {
15
+    protected boolean canWithdraw(float amount) {
16 16
         return getBalance() + OVERDRAFT_LIMIT >= amount;
17 17
     }
18 18
 }