Browse Source

commit to undo

mpierse 6 years ago
parent
commit
a16de2ea0a

+ 4
- 3
src/main/java/rocks/zipcode/atm/CashMachine.java View File

@@ -56,7 +56,7 @@ public class CashMachine {
56 56
 
57 57
     @Override
58 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 62
     private <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {
@@ -65,7 +65,8 @@ public class CashMachine {
65 65
             if (result.isSuccess()) {
66 66
                 T data = result.getData();
67 67
                 postAction.accept(data);
68
-            } else {
68
+            }
69
+            else {
69 70
                 String errorMessage = result.getErrorMessage();
70 71
                 throw new RuntimeException(errorMessage);
71 72
             }
@@ -74,7 +75,7 @@ public class CashMachine {
74 75
             alert.setTitle("Overdraw!");
75 76
             alert.setHeaderText("Not enough money!");
76 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 View File

@@ -27,6 +27,7 @@ public class CashMachineApp extends Application {
27 27
 
28 28
     private TextField field = new TextField();
29 29
     private CashMachine cashMachine = new CashMachine(new Bank());
30
+    private Bank bank = new Bank();
30 31
     GridPane grid;
31 32
 
32 33
     Stage primaryStage = new Stage();
@@ -51,7 +52,11 @@ public class CashMachineApp extends Application {
51 52
         grid.add(userID,0,1);
52 53
         TextField userTextField = new TextField();
53 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 60
        return grid;
56 61
     }
57 62
 

+ 11
- 6
src/main/java/rocks/zipcode/atm/bank/Bank.java View File

@@ -1,5 +1,6 @@
1 1
 package rocks.zipcode.atm.bank;
2 2
 
3
+import javafx.scene.control.Alert;
3 4
 import rocks.zipcode.atm.ActionResult;
4 5
 
5 6
 import java.util.HashMap;
@@ -14,18 +15,18 @@ public class Bank {
14 15
 
15 16
     public Bank() {
16 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 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 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 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,7 +36,7 @@ public class Bank {
35 36
         if (account != null) {
36 37
             return ActionResult.success(account.getAccountData());
37 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,7 +54,11 @@ public class Bank {
53 54
         if (ok) {
54 55
             return ActionResult.success(account.getAccountData());
55 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
 }