Browse Source

Not Broken

Added 2 popups for Overdrawn, Insufficient
Trying to disable/ enable buttons
Nick Satinover 6 years ago
parent
commit
58b9b181b7

+ 13
- 1
src/main/java/rocks/zipcode/atm/CashMachine.java View File

@@ -23,6 +23,7 @@ public class CashMachine {
23 23
     };
24 24
 
25 25
     public void login(int id) {
26
+
26 27
         tryCall(
27 28
                 () -> bank.getAccountById(id),
28 29
                 update
@@ -51,11 +52,22 @@ public class CashMachine {
51 52
         if (accountData != null) {
52 53
             accountData = null;
53 54
         }
55
+
56
+    }
57
+
58
+    public boolean isValidId(int id){
59
+        if (bank.isValidId(id)) {
60
+            return true;
61
+        } else {
62
+            return false;
63
+        }
54 64
     }
55 65
 
56 66
     @Override
57 67
     public String toString() {
58
-        return accountData != null ? accountData.toString() : "Try account 1000 or 2000 and click submit.";
68
+//
69
+        // if (accountData != null){isValidId();}
70
+        return accountData != null ? accountData.toString() : "Try account 1000, 2000, 6666, 7337\n and click submit.";
59 71
     }
60 72
 
61 73
     private <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {

+ 40
- 20
src/main/java/rocks/zipcode/atm/CashMachineApp.java View File

@@ -10,35 +10,38 @@ import javafx.scene.control.Button;
10 10
 import javafx.scene.control.TextArea;
11 11
 import javafx.scene.control.TextField;
12 12
 import javafx.stage.Stage;
13
+import javafx.scene.paint.Color;
13 14
 
14 15
 /**
15 16
  * @author ZipCodeWilmington
16 17
  */
17 18
 public class CashMachineApp extends Application {
19
+    Color blue = Color.rgb(0,0,255);
20
+    // Color green = Color.rgb(0,255,255);
18 21
 
19 22
     private CashMachine cashMachine = new CashMachine(new Bank());
20 23
 
21 24
     private TextField setAccountIdField = new TextField();
22
-    // private TextField setDeposit = new TextField();
23
-    // private TextField setAccountIdField = new TextField();
24
-    // private TextField setAccountIdField = new TextField();
25
+    private TextField setDepositField = new TextField();
26
+    private TextField setWithdrawField = new TextField();
25 27
 
26 28
     private Parent createContent() {
27
-        setAccountIdField.setMinSize(220, 40);
28
-        // seDeposit.setMinSize(220, 40);
29
-        // setAccountIdField.setMinSize(220, 40);
30
-        // setAccountIdField.setMinSize(220, 40);
31
-        
29
+        setAccountIdField.setMinSize(250, 40);
30
+        setDepositField.setMinSize(250, 40);
31
+        setWithdrawField.setMinSize(250, 40);
32
+
32 33
         GridPane gridPane = new GridPane();
33
-        gridPane.setPrefSize(600, 400);
34
-        gridPane.setAlignment(Pos.BASELINE_LEFT);
34
+        gridPane.setPrefSize(500, 400);
35
+        gridPane.setAlignment(Pos.CENTER);
36
+        gridPane.setStyle("-fx-background-color: Green;");
35 37
 
36 38
         TextArea areaInfo = new TextArea();
37
-        areaInfo.setMaxSize(220, 160);
39
+        areaInfo.setMaxSize(250, 160);
38 40
 
39 41
 
40 42
         Button btnSubmit = new Button("Set Account ID");
41
-        btnSubmit.setMinSize(220, 40);
43
+        btnSubmit.setMinSize(250, 40);
44
+        btnSubmit.setTextFill(blue);
42 45
         btnSubmit.setOnAction(e -> {
43 46
             int id = Integer.parseInt(setAccountIdField.getText());
44 47
             cashMachine.login(id);
@@ -47,25 +50,29 @@ public class CashMachineApp extends Application {
47 50
         });
48 51
 
49 52
         Button btnDeposit = new Button("Deposit");
50
-        btnDeposit.setMinSize(220, 40);
53
+        btnDeposit.setMinSize(250, 40);
54
+        btnDeposit.setTextFill(blue);
55
+//
56
+        // btnDeposit.setDisable(true);
51 57
         btnDeposit.setOnAction(e -> {
52
-            int amount = Integer.parseInt(setAccountIdField.getText());
58
+            int amount = Integer.parseInt(setDepositField.getText());
53 59
             cashMachine.deposit(amount);
54
-
55 60
             areaInfo.setText(cashMachine.toString());
56 61
         });
57 62
 
58 63
         Button btnWithdraw = new Button("Withdraw");
59
-        btnWithdraw.setMinSize(220, 40);
64
+        btnWithdraw.setMinSize(250, 40);
65
+        btnWithdraw.setTextFill(blue);
60 66
         btnWithdraw.setOnAction(e -> {
61
-            int amount = Integer.parseInt(setAccountIdField.getText());
67
+            int amount = Integer.parseInt(setWithdrawField.getText());
62 68
             cashMachine.withdraw(amount);
63 69
 
64 70
             areaInfo.setText(cashMachine.toString());
65 71
         });
66 72
 
67 73
         Button btnExit = new Button("Exit");
68
-        btnExit.setMinSize(220, 40);
74
+        btnExit.setMinSize(250, 160);
75
+        btnExit.setTextFill(blue);
69 76
         btnExit.setOnAction(e -> {
70 77
             cashMachine.exit();
71 78
 
@@ -78,17 +85,30 @@ public class CashMachineApp extends Application {
78 85
         GridPane.setConstraints(btnWithdraw, 0, 2);
79 86
         GridPane.setConstraints(btnExit, 0, 3);
80 87
         GridPane.setConstraints(setAccountIdField, 1, 0);
81
-        GridPane.setConstraints(areaInfo, 1, 4);
82
-        gridPane.getChildren().addAll(btnSubmit, btnDeposit, btnWithdraw, btnExit, setAccountIdField, areaInfo);
88
+        GridPane.setConstraints(setDepositField, 1, 1);
89
+        GridPane.setConstraints(setWithdrawField,1, 2);
90
+        GridPane.setConstraints(areaInfo, 1, 3);
91
+        gridPane.getChildren().addAll(btnSubmit, btnDeposit, btnWithdraw, btnExit,
92
+                setAccountIdField, setDepositField, setWithdrawField, areaInfo);
83 93
         return gridPane;
84 94
     }
85 95
 
86 96
     @Override
87 97
     public void start(Stage stage) throws Exception {
88 98
         stage.setScene(new Scene(createContent()));
99
+        stage.setTitle("Zip Code ATM");
89 100
         stage.show();
90 101
     }
91 102
 
103
+    public boolean isValidId(int id){
104
+        if (cashMachine.isValidId(id)) {
105
+            return true;
106
+        }
107
+        else {
108
+            return false;
109
+        }
110
+    }
111
+
92 112
     public static void main(String[] args) {
93 113
         launch(args);
94 114
     }

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

@@ -1,6 +1,8 @@
1 1
 package rocks.zipcode.atm.bank;
2 2
 
3 3
 import rocks.zipcode.atm.ActionResult;
4
+import rocks.zipcode.atm.CashMachine;
5
+import rocks.zipcode.atm.CashMachineApp;
4 6
 
5 7
 import java.util.HashMap;
6 8
 import java.util.Map;
@@ -32,11 +34,10 @@ public class Bank {
32 34
 
33 35
     public ActionResult<AccountData> getAccountById(int id) {
34 36
         Account account = accounts.get(id);
35
-
36 37
         if (account != null) {
37 38
             return ActionResult.success(account.getAccountData());
38 39
         } else {
39
-            return ActionResult.fail("No account with id: " + id + "\nTry account 1000 or 2000");
40
+            return ActionResult.fail("No account with id: " + id + "\nTry account 1000, 2000, 6666, 7337");
40 41
         }
41 42
     }
42 43
 
@@ -61,4 +62,14 @@ public class Bank {
61 62
             return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
62 63
         }
63 64
     }
65
+
66
+    public boolean isValidId(int id){
67
+        Account account = accounts.get(id);
68
+        if (account != null) {
69
+            return true;
70
+        } else {
71
+            return false;
72
+        }
73
+    }
74
+
64 75
 }