Parcourir la source

Not Broken

Added 2 popups for Overdrawn, Insufficient
Added disable/ enable buttons
Nick Satinover il y a 7 ans
Parent
révision
ae6b335212

+ 1
- 1
src/main/java/rocks/zipcode/atm/CashMachine.java Voir le fichier

@@ -67,7 +67,7 @@ public class CashMachine {
67 67
     public String toString() {
68 68
 //
69 69
         // if (accountData != null){isValidId();}
70
-        return accountData != null ? accountData.toString() : "Try account 1000, 2000, 6666, 7337\n and click submit.";
70
+        return accountData != null ? accountData.toString() : "Set Account ID:\n1000\n2000\n6666\n7337";
71 71
     }
72 72
 
73 73
     private <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {

+ 32
- 12
src/main/java/rocks/zipcode/atm/CashMachineApp.java Voir le fichier

@@ -39,21 +39,10 @@ public class CashMachineApp extends Application {
39 39
         areaInfo.setMaxSize(250, 160);
40 40
 
41 41
 
42
-        Button btnSubmit = new Button("Set Account ID");
43
-        btnSubmit.setMinSize(250, 40);
44
-        btnSubmit.setTextFill(blue);
45
-        btnSubmit.setOnAction(e -> {
46
-            int id = Integer.parseInt(setAccountIdField.getText());
47
-            cashMachine.login(id);
48
-
49
-            areaInfo.setText(cashMachine.toString());
50
-        });
51
-
52 42
         Button btnDeposit = new Button("Deposit");
53 43
         btnDeposit.setMinSize(250, 40);
54 44
         btnDeposit.setTextFill(blue);
55
-//
56
-        // btnDeposit.setDisable(true);
45
+        btnDeposit.setDisable(true);
57 46
         btnDeposit.setOnAction(e -> {
58 47
             int amount = Integer.parseInt(setDepositField.getText());
59 48
             cashMachine.deposit(amount);
@@ -63,6 +52,7 @@ public class CashMachineApp extends Application {
63 52
         Button btnWithdraw = new Button("Withdraw");
64 53
         btnWithdraw.setMinSize(250, 40);
65 54
         btnWithdraw.setTextFill(blue);
55
+        btnWithdraw.setDisable(true);
66 56
         btnWithdraw.setOnAction(e -> {
67 57
             int amount = Integer.parseInt(setWithdrawField.getText());
68 58
             cashMachine.withdraw(amount);
@@ -73,8 +63,32 @@ public class CashMachineApp extends Application {
73 63
         Button btnExit = new Button("Exit");
74 64
         btnExit.setMinSize(250, 160);
75 65
         btnExit.setTextFill(blue);
66
+        btnExit.setDisable(true);
76 67
         btnExit.setOnAction(e -> {
68
+            btnDeposit.setDisable(true);
69
+            btnWithdraw.setDisable(true);
70
+            btnExit.setDisable(true);
71
+            resetOnExit();
77 72
             cashMachine.exit();
73
+            areaInfo.setText(cashMachine.toString());
74
+        });
75
+
76
+        Button btnSubmit = new Button("Set Account ID");
77
+        btnSubmit.setMinSize(250, 40);
78
+        btnSubmit.setTextFill(blue);
79
+        btnSubmit.setOnAction(e -> {
80
+            int id = Integer.parseInt(setAccountIdField.getText());
81
+            if (isValidId(id)){
82
+                btnDeposit.setDisable(false);
83
+                btnWithdraw.setDisable(false);
84
+                btnExit.setDisable(false);
85
+            }
86
+            else {
87
+                btnDeposit.setDisable(true);
88
+                btnWithdraw.setDisable(true);
89
+                btnExit.setDisable(true);
90
+            }
91
+            cashMachine.login(id);
78 92
 
79 93
             areaInfo.setText(cashMachine.toString());
80 94
         });
@@ -109,6 +123,12 @@ public class CashMachineApp extends Application {
109 123
         }
110 124
     }
111 125
 
126
+    public void resetOnExit(){
127
+        setAccountIdField.clear();
128
+        setDepositField.clear();
129
+        setWithdrawField.clear();
130
+    }
131
+
112 132
     public static void main(String[] args) {
113 133
         launch(args);
114 134
     }