浏览代码

commit to undo

mpierse 6 年前
父节点
当前提交
a16de2ea0a

+ 4
- 3
src/main/java/rocks/zipcode/atm/CashMachine.java 查看文件

56
 
56
 
57
     @Override
57
     @Override
58
     public String toString() {
58
     public String toString() {
59
-        return accountData != null ? accountData.toString() : "Try account 1000 or 2000 and click submit.";
59
+        return accountData != null ? accountData.toString() : "Enter your account ID (1-4) to continue";
60
     }
60
     }
61
 
61
 
62
     private <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {
62
     private <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {
65
             if (result.isSuccess()) {
65
             if (result.isSuccess()) {
66
                 T data = result.getData();
66
                 T data = result.getData();
67
                 postAction.accept(data);
67
                 postAction.accept(data);
68
-            } else {
68
+            }
69
+            else {
69
                 String errorMessage = result.getErrorMessage();
70
                 String errorMessage = result.getErrorMessage();
70
                 throw new RuntimeException(errorMessage);
71
                 throw new RuntimeException(errorMessage);
71
             }
72
             }
74
             alert.setTitle("Overdraw!");
75
             alert.setTitle("Overdraw!");
75
             alert.setHeaderText("Not enough money!");
76
             alert.setHeaderText("Not enough money!");
76
             alert.setContentText("You do not have enough money in your account to complete this transaction.");
77
             alert.setContentText("You do not have enough money in your account to complete this transaction.");
77
-            //System.out.println("Error: " + e.getMessage());
78
+            System.out.println("Error: " + e.getMessage());
78
         }
79
         }
79
     }
80
     }
80
 }
81
 }

+ 6
- 1
src/main/java/rocks/zipcode/atm/CashMachineApp.java 查看文件

27
 
27
 
28
     private TextField field = new TextField();
28
     private TextField field = new TextField();
29
     private CashMachine cashMachine = new CashMachine(new Bank());
29
     private CashMachine cashMachine = new CashMachine(new Bank());
30
+    private Bank bank = new Bank();
30
     GridPane grid;
31
     GridPane grid;
31
 
32
 
32
     Stage primaryStage = new Stage();
33
     Stage primaryStage = new Stage();
51
         grid.add(userID,0,1);
52
         grid.add(userID,0,1);
52
         TextField userTextField = new TextField();
53
         TextField userTextField = new TextField();
53
         grid.add(userTextField,1,1);
54
         grid.add(userTextField,1,1);
54
-        btn.setOnAction(e->primaryStage.setScene(scene2));
55
+        btn.setOnAction(e->{
56
+        int id = Integer.parseInt(userTextField.getText());
57
+        cashMachine.login(id);
58
+        bank.getAccountById(id);
59
+        primaryStage.setScene(scene2);} );
55
        return grid;
60
        return grid;
56
     }
61
     }
57
 
62
 

+ 11
- 6
src/main/java/rocks/zipcode/atm/bank/Bank.java 查看文件

1
 package rocks.zipcode.atm.bank;
1
 package rocks.zipcode.atm.bank;
2
 
2
 
3
+import javafx.scene.control.Alert;
3
 import rocks.zipcode.atm.ActionResult;
4
 import rocks.zipcode.atm.ActionResult;
4
 
5
 
5
 import java.util.HashMap;
6
 import java.util.HashMap;
14
 
15
 
15
     public Bank() {
16
     public Bank() {
16
         accounts.put(1000, new BasicAccount(new AccountData(
17
         accounts.put(1000, new BasicAccount(new AccountData(
17
-                1000, "Example 1", "example1@gmail.com", 500
18
+                1, "Doug Funny", "beetz@gmail.com", 500
18
         )));
19
         )));
19
 
20
 
20
         accounts.put(2000, new PremiumAccount(new AccountData(
21
         accounts.put(2000, new PremiumAccount(new AccountData(
21
-                2000, "Example 2", "example2@gmail.com", 200
22
+                2, "Bugs Bunny", "WatsUpDoc@gmail.com", 200
22
         )));
23
         )));
23
 
24
 
24
         accounts.put(3000, new PremiumAccount(new AccountData(
25
         accounts.put(3000, new PremiumAccount(new AccountData(
25
-                3000, "Scooby Doo", "scoobs@gmail.com", 50
26
+                3, "Scooby Doo", "scoobs@gmail.com", 50
26
         )));
27
         )));
27
         accounts.put(4000, new BasicAccount(new AccountData(
28
         accounts.put(4000, new BasicAccount(new AccountData(
28
-                4000, "Road Runner", "beebbeeb@gmail.com", 2000
29
+                4, "Road Runner", "beebbeeb@gmail.com", 2000
29
         )));
30
         )));
30
     }
31
     }
31
 
32
 
35
         if (account != null) {
36
         if (account != null) {
36
             return ActionResult.success(account.getAccountData());
37
             return ActionResult.success(account.getAccountData());
37
         } else {
38
         } else {
38
-            return ActionResult.fail("No account with id: " + id + "\nTry account 1000 or 2000");
39
+            return ActionResult.fail("No account with id: " + id );
39
         }
40
         }
40
     }
41
     }
41
 
42
 
53
         if (ok) {
54
         if (ok) {
54
             return ActionResult.success(account.getAccountData());
55
             return ActionResult.success(account.getAccountData());
55
         } else {
56
         } else {
56
-            return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
57
+            Alert alert = new Alert(Alert.AlertType.ERROR);
58
+            alert.setTitle("Overdraw!");
59
+            alert.setHeaderText("Not enough money!");
60
+            alert.setContentText("You do not have enough money in your account to complete this transaction.");
61
+            return ActionResult.fail("Insufficient Funds");
57
         }
62
         }
58
     }
63
     }
59
 }
64
 }