Przeglądaj źródła

Added notifiation alert for overdraft

Trinh Tong 8 lat temu
rodzic
commit
4953b82524

+ 4
- 4
src/main/java/rocks/zipcode/atm/CashMachine.java Wyświetl plik

@@ -1,5 +1,6 @@
1 1
 package rocks.zipcode.atm;
2 2
 
3
+import javafx.scene.control.Alert;
3 4
 import rocks.zipcode.atm.bank.AccountData;
4 5
 import rocks.zipcode.atm.bank.Bank;
5 6
 
@@ -37,10 +38,6 @@ public class CashMachine {
37 38
                     update
38 39
             );
39 40
 
40
-            if (accountData.getBalance() < 0) {
41
-                // overdraft amount
42
-
43
-            }
44 41
         }
45 42
     }
46 43
 
@@ -50,6 +47,9 @@ public class CashMachine {
50 47
                     () -> bank.withdraw(accountData, amount),
51 48
                     update
52 49
             );
50
+
51
+            // Over draft check for alert message?
52
+
53 53
         }
54 54
     }
55 55
 

+ 0
- 2
src/main/java/rocks/zipcode/atm/CashMachineApp.java Wyświetl plik

@@ -63,8 +63,6 @@ public class CashMachineApp extends Application {
63 63
             float amount = Float.parseFloat(field.getText());
64 64
             cashMachine.withdraw(amount);
65 65
 
66
-//            withdrawAlert.setContentText("Testing, 1, 2, 3!");
67
-//            withdrawAlert.showAndWait();
68 66
             areaInfo.setText(cashMachine.toString());
69 67
         });
70 68
 

+ 11
- 0
src/main/java/rocks/zipcode/atm/bank/Bank.java Wyświetl plik

@@ -1,5 +1,7 @@
1 1
 package rocks.zipcode.atm.bank;
2 2
 
3
+import javafx.scene.control.Alert;
4
+import javafx.scene.control.ButtonType;
3 5
 import rocks.zipcode.atm.ActionResult;
4 6
 
5 7
 import java.awt.event.ActionEvent;
@@ -45,11 +47,20 @@ public class Bank {
45 47
     }
46 48
 
47 49
     public ActionResult<AccountData> withdraw(AccountData accountData, float amount) {
50
+        // this gets the ID from accountdata and then gets the account in the hashmap
48 51
         Account account = accounts.get(accountData.getId());
49 52
         boolean ok = account.withdraw(amount);
50 53
 
51 54
         if (ok) {
55
+
56
+            if (account.getBalance() < 0) {
57
+                Alert overDraftAlert = new Alert(Alert.AlertType.INFORMATION);
58
+                overDraftAlert.setContentText("This transaction will overdraft your account.");
59
+                overDraftAlert.showAndWait();
60
+            }
61
+
52 62
             return ActionResult.success(account.getAccountData());
63
+
53 64
         } else {
54 65
             return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
55 66
         }