浏览代码

Not Broken

Nick Satinover 6 年前
父节点
当前提交
a64e99b296

+ 4
- 0
src/main/java/rocks/zipcode/atm/ActionResult.java 查看文件

@@ -32,6 +32,10 @@ public class ActionResult<T> {
32 32
         return new ActionResult<E>(data);
33 33
     }
34 34
 
35
+    public static <E> ActionResult<E> overdrawn(String overdrawnMessage) {
36
+        return new ActionResult<E>(overdrawnMessage);
37
+    }
38
+
35 39
     public static <E> ActionResult<E> fail(String errorMessage) {
36 40
         return new ActionResult<E>(errorMessage);
37 41
     }

+ 32
- 15
src/main/java/rocks/zipcode/atm/CashMachineApp.java 查看文件

@@ -1,5 +1,7 @@
1 1
 package rocks.zipcode.atm;
2 2
 
3
+import javafx.geometry.Pos;
4
+import javafx.scene.layout.GridPane;
3 5
 import rocks.zipcode.atm.bank.Bank;
4 6
 import javafx.application.Application;
5 7
 import javafx.scene.Parent;
@@ -7,63 +9,78 @@ import javafx.scene.Scene;
7 9
 import javafx.scene.control.Button;
8 10
 import javafx.scene.control.TextArea;
9 11
 import javafx.scene.control.TextField;
10
-import javafx.scene.layout.VBox;
11 12
 import javafx.stage.Stage;
12
-import javafx.scene.layout.FlowPane;
13 13
 
14 14
 /**
15 15
  * @author ZipCodeWilmington
16 16
  */
17 17
 public class CashMachineApp extends Application {
18 18
 
19
-    private TextField field = new TextField();
20 19
     private CashMachine cashMachine = new CashMachine(new Bank());
21 20
 
21
+    private TextField setAccountIdField = new TextField();
22
+    // private TextField setDeposit = new TextField();
23
+    // private TextField setAccountIdField = new TextField();
24
+    // private TextField setAccountIdField = new TextField();
25
+
22 26
     private Parent createContent() {
23
-        VBox vbox = new VBox(10);
24
-        vbox.setPrefSize(600, 600);
27
+        setAccountIdField.setMinSize(220, 40);
28
+        // seDeposit.setMinSize(220, 40);
29
+        // setAccountIdField.setMinSize(220, 40);
30
+        // setAccountIdField.setMinSize(220, 40);
31
+        
32
+        GridPane gridPane = new GridPane();
33
+        gridPane.setPrefSize(600, 400);
34
+        gridPane.setAlignment(Pos.BASELINE_LEFT);
25 35
 
26 36
         TextArea areaInfo = new TextArea();
37
+        areaInfo.setMaxSize(220, 160);
38
+
27 39
 
28 40
         Button btnSubmit = new Button("Set Account ID");
41
+        btnSubmit.setMinSize(220, 40);
29 42
         btnSubmit.setOnAction(e -> {
30
-            int id = Integer.parseInt(field.getText());
43
+            int id = Integer.parseInt(setAccountIdField.getText());
31 44
             cashMachine.login(id);
32 45
 
33 46
             areaInfo.setText(cashMachine.toString());
34 47
         });
35 48
 
36 49
         Button btnDeposit = new Button("Deposit");
50
+        btnDeposit.setMinSize(220, 40);
37 51
         btnDeposit.setOnAction(e -> {
38
-            int amount = Integer.parseInt(field.getText());
52
+            int amount = Integer.parseInt(setAccountIdField.getText());
39 53
             cashMachine.deposit(amount);
40 54
 
41 55
             areaInfo.setText(cashMachine.toString());
42 56
         });
43 57
 
44 58
         Button btnWithdraw = new Button("Withdraw");
59
+        btnWithdraw.setMinSize(220, 40);
45 60
         btnWithdraw.setOnAction(e -> {
46
-            int amount = Integer.parseInt(field.getText());
61
+            int amount = Integer.parseInt(setAccountIdField.getText());
47 62
             cashMachine.withdraw(amount);
48 63
 
49 64
             areaInfo.setText(cashMachine.toString());
50 65
         });
51 66
 
52 67
         Button btnExit = new Button("Exit");
68
+        btnExit.setMinSize(220, 40);
53 69
         btnExit.setOnAction(e -> {
54 70
             cashMachine.exit();
55 71
 
56 72
             areaInfo.setText(cashMachine.toString());
57 73
         });
58 74
 
59
-        FlowPane flowpane = new FlowPane();
60 75
 
61
-        flowpane.getChildren().add(btnSubmit);
62
-        flowpane.getChildren().add(btnDeposit);
63
-        flowpane.getChildren().add(btnWithdraw);
64
-        flowpane.getChildren().add(btnExit);
65
-        vbox.getChildren().addAll(field, flowpane, areaInfo);
66
-        return vbox;
76
+        GridPane.setConstraints(btnSubmit, 0, 0);
77
+        GridPane.setConstraints(btnDeposit, 0, 1);
78
+        GridPane.setConstraints(btnWithdraw, 0, 2);
79
+        GridPane.setConstraints(btnExit, 0, 3);
80
+        GridPane.setConstraints(setAccountIdField, 1, 0);
81
+        GridPane.setConstraints(areaInfo, 1, 4);
82
+        gridPane.getChildren().addAll(btnSubmit, btnDeposit, btnWithdraw, btnExit, setAccountIdField, areaInfo);
83
+        return gridPane;
67 84
     }
68 85
 
69 86
     @Override

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

@@ -20,6 +20,14 @@ public class Bank {
20 20
         accounts.put(2000, new PremiumAccount(new AccountData(
21 21
                 2000, "Example 2", "example2@gmail.com", 200
22 22
         )));
23
+
24
+        accounts.put(6666, new PremiumAccount(new AccountData(
25
+                6666, "Nick Satinover", "nsatinover@gmail.com", 20000
26
+        )));
27
+
28
+        accounts.put(7337, new BasicAccount(new AccountData(
29
+                7337, "Kris HaHaYourBroke", "kris@onedollar.com", 1
30
+        )));
23 31
     }
24 32
 
25 33
     public ActionResult<AccountData> getAccountById(int id) {
@@ -44,8 +52,12 @@ public class Bank {
44 52
         boolean ok = account.withdraw(amount);
45 53
 
46 54
         if (ok) {
55
+            if (account.getBalance() < 0) {
56
+                Overdraft.popupMessage("Overdraft", "Warning, your account is now in overdraft");
57
+            }
47 58
             return ActionResult.success(account.getAccountData());
48 59
         } else {
60
+            Overdraft.popupMessage("Declined", "Declined, account contains insufficient funds");
49 61
             return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
50 62
         }
51 63
     }

+ 54
- 0
src/main/java/rocks/zipcode/atm/bank/Overdraft.java 查看文件

@@ -0,0 +1,54 @@
1
+package rocks.zipcode.atm.bank;
2
+
3
+import javafx.scene.control.Button;
4
+import javafx.scene.control.Label;
5
+import javafx.stage.Stage;
6
+import javafx.scene.*;
7
+import javafx.scene.layout.*;
8
+import javafx.scene.control.*;
9
+import javafx.geometry.*;
10
+import javafx.stage.Modality;
11
+
12
+import java.awt.*;
13
+
14
+public class Overdraft {
15
+
16
+    public static void popupMessage(String title, String message){
17
+        // "Warning, your account is now in popupMessage";
18
+        Stage window = new Stage();
19
+        window.initModality(Modality.APPLICATION_MODAL); //Block Input until window closed/ resolved
20
+        window.setTitle(title);
21
+        window.setMinWidth(250);
22
+
23
+        Label label = new Label();
24
+        label.setText(message);
25
+
26
+        Button closeButton = new Button("Close");
27
+        closeButton.setOnAction(e -> window.close());
28
+
29
+        VBox layout = new VBox(10);
30
+        layout.getChildren().addAll(label, closeButton);
31
+        layout.setAlignment(Pos.CENTER);
32
+
33
+        Scene scene = new Scene(layout);
34
+        window.setScene(scene);
35
+        window.showAndWait();
36
+
37
+    }
38
+}
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+

+ 1
- 1
src/main/java/rocks/zipcode/atm/bank/PremiumAccount.java 查看文件

@@ -5,7 +5,7 @@ package rocks.zipcode.atm.bank;
5 5
  */
6 6
 public class PremiumAccount extends Account {
7 7
 
8
-    private static final int OVERDRAFT_LIMIT = 100;
8
+    private static final int OVERDRAFT_LIMIT = 1000;
9 9
 
10 10
     public PremiumAccount(AccountData accountData) {
11 11
         super(accountData);