Parcourir la source

Not Broken

Added 2 popups for Overdrawn, Insufficient
Trying to disable/ enable buttons
Nick Satinover il y a 6 ans
Parent
révision
58b9b181b7

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

23
     };
23
     };
24
 
24
 
25
     public void login(int id) {
25
     public void login(int id) {
26
+
26
         tryCall(
27
         tryCall(
27
                 () -> bank.getAccountById(id),
28
                 () -> bank.getAccountById(id),
28
                 update
29
                 update
51
         if (accountData != null) {
52
         if (accountData != null) {
52
             accountData = null;
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
     @Override
66
     @Override
57
     public String toString() {
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
     private <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {
73
     private <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {

+ 40
- 20
src/main/java/rocks/zipcode/atm/CashMachineApp.java Voir le fichier

10
 import javafx.scene.control.TextArea;
10
 import javafx.scene.control.TextArea;
11
 import javafx.scene.control.TextField;
11
 import javafx.scene.control.TextField;
12
 import javafx.stage.Stage;
12
 import javafx.stage.Stage;
13
+import javafx.scene.paint.Color;
13
 
14
 
14
 /**
15
 /**
15
  * @author ZipCodeWilmington
16
  * @author ZipCodeWilmington
16
  */
17
  */
17
 public class CashMachineApp extends Application {
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
     private CashMachine cashMachine = new CashMachine(new Bank());
22
     private CashMachine cashMachine = new CashMachine(new Bank());
20
 
23
 
21
     private TextField setAccountIdField = new TextField();
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
     private Parent createContent() {
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
         GridPane gridPane = new GridPane();
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
         TextArea areaInfo = new TextArea();
38
         TextArea areaInfo = new TextArea();
37
-        areaInfo.setMaxSize(220, 160);
39
+        areaInfo.setMaxSize(250, 160);
38
 
40
 
39
 
41
 
40
         Button btnSubmit = new Button("Set Account ID");
42
         Button btnSubmit = new Button("Set Account ID");
41
-        btnSubmit.setMinSize(220, 40);
43
+        btnSubmit.setMinSize(250, 40);
44
+        btnSubmit.setTextFill(blue);
42
         btnSubmit.setOnAction(e -> {
45
         btnSubmit.setOnAction(e -> {
43
             int id = Integer.parseInt(setAccountIdField.getText());
46
             int id = Integer.parseInt(setAccountIdField.getText());
44
             cashMachine.login(id);
47
             cashMachine.login(id);
47
         });
50
         });
48
 
51
 
49
         Button btnDeposit = new Button("Deposit");
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
         btnDeposit.setOnAction(e -> {
57
         btnDeposit.setOnAction(e -> {
52
-            int amount = Integer.parseInt(setAccountIdField.getText());
58
+            int amount = Integer.parseInt(setDepositField.getText());
53
             cashMachine.deposit(amount);
59
             cashMachine.deposit(amount);
54
-
55
             areaInfo.setText(cashMachine.toString());
60
             areaInfo.setText(cashMachine.toString());
56
         });
61
         });
57
 
62
 
58
         Button btnWithdraw = new Button("Withdraw");
63
         Button btnWithdraw = new Button("Withdraw");
59
-        btnWithdraw.setMinSize(220, 40);
64
+        btnWithdraw.setMinSize(250, 40);
65
+        btnWithdraw.setTextFill(blue);
60
         btnWithdraw.setOnAction(e -> {
66
         btnWithdraw.setOnAction(e -> {
61
-            int amount = Integer.parseInt(setAccountIdField.getText());
67
+            int amount = Integer.parseInt(setWithdrawField.getText());
62
             cashMachine.withdraw(amount);
68
             cashMachine.withdraw(amount);
63
 
69
 
64
             areaInfo.setText(cashMachine.toString());
70
             areaInfo.setText(cashMachine.toString());
65
         });
71
         });
66
 
72
 
67
         Button btnExit = new Button("Exit");
73
         Button btnExit = new Button("Exit");
68
-        btnExit.setMinSize(220, 40);
74
+        btnExit.setMinSize(250, 160);
75
+        btnExit.setTextFill(blue);
69
         btnExit.setOnAction(e -> {
76
         btnExit.setOnAction(e -> {
70
             cashMachine.exit();
77
             cashMachine.exit();
71
 
78
 
78
         GridPane.setConstraints(btnWithdraw, 0, 2);
85
         GridPane.setConstraints(btnWithdraw, 0, 2);
79
         GridPane.setConstraints(btnExit, 0, 3);
86
         GridPane.setConstraints(btnExit, 0, 3);
80
         GridPane.setConstraints(setAccountIdField, 1, 0);
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
         return gridPane;
93
         return gridPane;
84
     }
94
     }
85
 
95
 
86
     @Override
96
     @Override
87
     public void start(Stage stage) throws Exception {
97
     public void start(Stage stage) throws Exception {
88
         stage.setScene(new Scene(createContent()));
98
         stage.setScene(new Scene(createContent()));
99
+        stage.setTitle("Zip Code ATM");
89
         stage.show();
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
     public static void main(String[] args) {
112
     public static void main(String[] args) {
93
         launch(args);
113
         launch(args);
94
     }
114
     }

+ 13
- 2
src/main/java/rocks/zipcode/atm/bank/Bank.java Voir le fichier

1
 package rocks.zipcode.atm.bank;
1
 package rocks.zipcode.atm.bank;
2
 
2
 
3
 import rocks.zipcode.atm.ActionResult;
3
 import rocks.zipcode.atm.ActionResult;
4
+import rocks.zipcode.atm.CashMachine;
5
+import rocks.zipcode.atm.CashMachineApp;
4
 
6
 
5
 import java.util.HashMap;
7
 import java.util.HashMap;
6
 import java.util.Map;
8
 import java.util.Map;
32
 
34
 
33
     public ActionResult<AccountData> getAccountById(int id) {
35
     public ActionResult<AccountData> getAccountById(int id) {
34
         Account account = accounts.get(id);
36
         Account account = accounts.get(id);
35
-
36
         if (account != null) {
37
         if (account != null) {
37
             return ActionResult.success(account.getAccountData());
38
             return ActionResult.success(account.getAccountData());
38
         } else {
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
             return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
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
 }