Browse Source

Separated return information fields

Lauren Green 6 years ago
parent
commit
7ae95c21d7

+ 20
- 0
src/main/java/rocks/zipcode/atm/CashMachine.java View File

@@ -1,5 +1,6 @@
1 1
 package rocks.zipcode.atm;
2 2
 
3
+import com.sun.javafx.binding.StringFormatter;
3 4
 import javafx.collections.FXCollections;
4 5
 import javafx.collections.ObservableList;
5 6
 import rocks.zipcode.atm.bank.AccountData;
@@ -25,6 +26,24 @@ public class CashMachine {
25 26
 
26 27
     }
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();
45
+    }
46
+
28 47
     private Consumer<AccountData> update = data -> {
29 48
         accountData = data;
30 49
     };
@@ -72,6 +91,7 @@ public class CashMachine {
72 91
                     () -> bank.withdraw(accountData, amount),
73 92
                     update
74 93
             );
94
+
75 95
         }
76 96
     }
77 97
 

+ 128
- 28
src/main/java/rocks/zipcode/atm/CashMachineApp.java View File

@@ -36,11 +36,64 @@ public class CashMachineApp extends Application {
36 36
 
37 37
     private Parent createContent() {
38 38
         VBox vbox = new VBox(10);
39
-        vbox.setPrefSize(600, 600);
40
-        vbox.setStyle("-fx-background-color: mediumaquamarine; -fx-padding: 20; -fx-font-size: 20;");
39
+        vbox.setPrefSize(600, 750);
40
+        vbox.setStyle("-fx-background-color: lightslategray; -fx-padding: 20; -fx-font-size: 20;");
41 41
 
42
-        TextArea areaInfo = new TextArea();
43 42
 
43
+        TextField areaAccountId = new TextField();
44
+        areaAccountId.setStyle("-fx-background-color: lightsteelblue;");
45
+        areaAccountId.setManaged(false);
46
+
47
+        Label accountId = new Label("Account ID:");
48
+        accountId.setManaged(false);
49
+
50
+       // HBox accountIdInfo = new HBox(5);
51
+        //accountIdInfo.getChildren().addAll(accountId, areaAccountId);
52
+
53
+        TextField areaAccountName = new TextField();
54
+        areaAccountName.setManaged(false);
55
+        areaAccountName.setStyle("-fx-background-color: lightsteelblue;");
56
+
57
+        Label accountName = new Label("Account Holder:");
58
+        accountName.setManaged(false);
59
+
60
+        //HBox nameInfo = new HBox(5);
61
+        //nameInfo.getChildren().addAll(accountName, areaAccountName);
62
+
63
+        TextField areaAccountEmail = new TextField();
64
+        areaAccountEmail.setManaged(false);
65
+        areaAccountEmail.setStyle("-fx-background-color: lightsteelblue;");
66
+
67
+        Label accountEmail = new Label("Email:");
68
+        accountEmail.setManaged(false);
69
+
70
+        //HBox accountEmailInfo = new HBox(5);
71
+        //accountEmailInfo.getChildren().addAll(accountEmail, areaAccountEmail);
72
+
73
+        TextField areaAccountAmount = new TextField();
74
+        areaAccountAmount.setManaged(false);
75
+        areaAccountAmount.setStyle("-fx-background-color: mediumturquoise;");
76
+
77
+        Label accountBalance = new Label("Balance:");
78
+        accountBalance.setManaged(false);
79
+
80
+        /*
81
+        HBox accountBalanceInfo = new HBox(5);
82
+        accountBalanceInfo.getChildren().addAll(accountBalance, areaAccountAmount);
83
+
84
+        accountIdInfo.setPrefSize(100, 100);
85
+        accountIdInfo.setStyle("-fx-background-color: mediumaquamarine; -fx-padding: 20; -fx-font-size: 20;");
86
+        */
87
+
88
+        field2.setManaged(false);
89
+
90
+        Label fieldLabel2 = new Label("Amount:");
91
+        fieldLabel2.setManaged(false);
92
+        Label fieldLabel = new Label("Select Your Account Number:");
93
+
94
+        field.setStyle("-fx-background-color: lightgrey;");
95
+        field2.setStyle("-fx-background-color: lightgrey;");
96
+        Label passwordLabel = new Label("Password:");
44 97
 
45 98
 
46 99
         //Make Button Do something.
@@ -53,56 +106,109 @@ public class CashMachineApp extends Application {
53 106
 */
54 107
 
55 108
         Button btnDeposit = new Button("Deposit");
56
-        btnDeposit.setDisable(true);
109
+        btnDeposit.setManaged(false);
57 110
         btnDeposit.setOnAction(e -> {
58 111
             float amount = Float.parseFloat(field2.getText());
59 112
             cashMachine.deposit(amount);
60 113
 
61
-            areaInfo.setText(cashMachine.toString());
114
+            areaAccountAmount.setText(Float.toString(cashMachine.getBalance()));
62 115
         });
63 116
 
64 117
 
65 118
         Button btnWithdraw = new Button("Withdraw");
66
-        btnWithdraw.setDisable(true);
119
+        btnWithdraw.setManaged(false);
67 120
         btnWithdraw.setOnAction(e -> {
68 121
             float amount = Float.parseFloat(field2.getText());
69 122
             cashMachine.withdraw(amount);
70
-            areaInfo.setText(cashMachine.toString());
123
+            areaAccountAmount.setText(Float.toString(cashMachine.getBalance()));
71 124
         });
72 125
 
73 126
         Button btnResetPassword = new Button("Reset Password");
74
-        btnResetPassword.setDisable(true);
127
+        btnResetPassword.setManaged(false);
75 128
         btnResetPassword.setOnAction(e -> {
76 129
             int id = Integer.parseInt(accountNumbers.getValue().toString());
77 130
             String password = field.getText();
78 131
             cashMachine.resetPassword(id, password);
79
-            areaInfo.setText(cashMachine.message("Password Reset."));
132
+            passwordLabel.setText(cashMachine.message("Password Reset."));
80 133
         });
81 134
 
82 135
         Button btnExit = new Button("Log Out");
136
+        btnExit.setManaged(false);
83 137
         btnExit.setOnAction(e -> {
84 138
             cashMachine.exit();
85 139
             field.clear();
86 140
             field2.clear();
87
-            areaInfo.clear();
88
-            btnDeposit.setDisable(true);
89
-            btnWithdraw.setDisable(true);
90
-            btnResetPassword.setDisable(true);
141
+            areaAccountAmount.clear();
142
+            areaAccountEmail.clear();
143
+            areaAccountId.clear();
144
+            areaAccountName.clear();
145
+            passwordLabel.setText("Password:");
146
+
147
+
148
+            field2.setVisible(false);
149
+            fieldLabel2.setVisible(false);
150
+            btnDeposit.setVisible(false);
151
+            btnWithdraw.setVisible(false);
152
+            btnExit.setVisible(false);
153
+            btnResetPassword.setVisible(false);
154
+
155
+            areaAccountAmount.setVisible(false);
156
+            areaAccountEmail.setVisible(false);
157
+            areaAccountId.setVisible(false);
158
+            areaAccountName.setVisible(false);
159
+
160
+            accountBalance.setVisible(false);
161
+            accountEmail.setVisible(false);
162
+            accountId.setVisible(false);
163
+            accountName.setVisible(false);
91 164
         });
92 165
 
93 166
         Button btnSubmit = new Button("Enter");
94 167
         btnSubmit.setOnAction(e -> {
95 168
             int id = Integer.parseInt(accountNumbers.getValue().toString());
96
-            String password = field.getText();
97
-            if(cashMachine.checkPassword(id, password)) {
169
+            String passwordInput = field.getText();
170
+            if(cashMachine.checkPassword(id, passwordInput)) {
98 171
                 cashMachine.login(id);
99
-                areaInfo.setText(cashMachine.toString());
100
-                btnDeposit.setDisable(false);
101
-                btnWithdraw.setDisable(false);
102
-                btnResetPassword.setDisable(false);
103
-                password = "New Password:";
172
+                areaAccountAmount.setText(Float.toString(cashMachine.getBalance()));
173
+                areaAccountEmail.setText(cashMachine.getEmail());
174
+                areaAccountId.setText(Integer.toString(cashMachine.getId()));
175
+                areaAccountName.setText(cashMachine.getName());
176
+                areaAccountAmount.setManaged(true);
177
+                areaAccountEmail.setManaged(true);
178
+                areaAccountId.setManaged(true);
179
+                areaAccountName.setManaged(true);
180
+                accountId.setManaged(true);
181
+                accountName.setManaged(true);
182
+                accountEmail.setManaged(true);
183
+                accountBalance.setManaged(true);
184
+                passwordLabel.setText("New Password:");
185
+                btnDeposit.setManaged(true);
186
+                btnWithdraw.setManaged(true);
187
+                btnExit.setManaged(true);
188
+                btnResetPassword.setManaged(true);
189
+                accountId.setManaged(true);
190
+                field2.setManaged(true);
191
+                fieldLabel2.setManaged(true);
192
+
193
+                field2.setVisible(true);
194
+                fieldLabel2.setVisible(true);
195
+                btnDeposit.setVisible(true);
196
+                btnWithdraw.setVisible(true);
197
+                btnExit.setVisible(true);
198
+                btnResetPassword.setVisible(true);
199
+
200
+                areaAccountAmount.setVisible(true);
201
+                areaAccountEmail.setVisible(true);
202
+                areaAccountId.setVisible(true);
203
+                areaAccountName.setVisible(true);
204
+
205
+                accountBalance.setVisible(true);
206
+                accountEmail.setVisible(true);
207
+                accountId.setVisible(true);
208
+                accountName.setVisible(true);
209
+
104 210
             } else {
105
-                areaInfo.setText(cashMachine.message("Incorrect Password.  Try Again."));
211
+                areaAccountId.setText(cashMachine.message("Incorrect Password.  Try Again."));
106 212
             }
107 213
         });
108 214
 
@@ -125,14 +231,8 @@ public class CashMachineApp extends Application {
125 231
         flowpane2.getChildren().add(btnDeposit);
126 232
         flowpane2.getChildren().add(btnWithdraw);
127 233
         flowpane2.getChildren().add(btnExit);
128
-        Label fieldLabel2 = new Label("Amount:");
129
-        Label accountInfo2 = new Label("Account Info:");
130 234
 
131
-        field.setStyle("-fx-background-color: lightgrey;");
132
-        field2.setStyle("-fx-background-color: lightgrey;");
133
-        Label fieldLabel = new Label("Account Number:");
134
-        Label password = new Label("Password:");
135
-        vbox.getChildren().addAll(fieldLabel, accountNumbers, password, field, flowpane, fieldLabel2, field2, flowpane2, accountInfo2, areaInfo);
235
+        vbox.getChildren().addAll(fieldLabel, accountNumbers, passwordLabel, field, flowpane, fieldLabel2, field2, flowpane2, accountId, areaAccountId, accountName, areaAccountName, accountEmail, areaAccountEmail, accountBalance, areaAccountAmount);
136 236
 
137 237
 
138 238
 

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

@@ -36,7 +36,7 @@ public final class AccountData {
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 42
                 "Balance: $" + String.format("%,.2f", balance);

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

@@ -81,7 +81,7 @@ public class Bank {
81 81
         passwords.put(1900, "password");
82 82
 
83 83
         accounts.put(2000, new PremiumAccount(new AccountData(
84
-                2000, "Frankie Smit", "frank@gmail.com", 2040
84
+                2000, "Frankie Smith", "frank@gmail.com", 2040
85 85
         )));
86 86
 
87 87
         passwords.put(2000, "password");
@@ -148,7 +148,6 @@ public class Bank {
148 148
     public ActionResult<AccountData> withdraw(AccountData accountData, float amount) {
149 149
         Account account = accounts.get(accountData.getId());
150 150
         boolean ok = account.withdraw(amount);
151
-
152 151
         if (ok) {
153 152
             return ActionResult.success(account.getAccountData());
154 153
         } else {