Lauren Green 6 лет назад
Родитель
Сommit
fb7ff2e576

+ 2
- 1
src/main/java/rocks/zipcode/atm/CashMachine.java Просмотреть файл

@@ -55,9 +55,10 @@ public class CashMachine {
55 55
 
56 56
     @Override
57 57
     public String toString() {
58
-        return accountData != null ? accountData.toString() : "Try account 1000 or 2000 and click submit.";
58
+        return accountData != null ? accountData.toString() : "Incorrect account number. \nTry again or click 'Forgot Account Number'";
59 59
     }
60 60
 
61
+
61 62
     private <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {
62 63
         try {
63 64
             ActionResult<T> result = action.get();

+ 54
- 10
src/main/java/rocks/zipcode/atm/CashMachineApp.java Просмотреть файл

@@ -1,5 +1,7 @@
1 1
 package rocks.zipcode.atm;
2 2
 
3
+import javafx.scene.control.Label;
4
+import javafx.stage.StageStyle;
3 5
 import rocks.zipcode.atm.bank.Bank;
4 6
 import javafx.application.Application;
5 7
 import javafx.scene.Parent;
@@ -17,25 +19,44 @@ import javafx.scene.layout.FlowPane;
17 19
 public class CashMachineApp extends Application {
18 20
 
19 21
     private TextField field = new TextField();
22
+    private TextField field2 = new TextField();
20 23
     private CashMachine cashMachine = new CashMachine(new Bank());
21 24
 
25
+
22 26
     private Parent createContent() {
23 27
         VBox vbox = new VBox(10);
24 28
         vbox.setPrefSize(600, 600);
29
+        vbox.setStyle("-fx-background-color: silver; -fx-padding: 20; -fx-font-size: 20;");
25 30
 
26 31
         TextArea areaInfo = new TextArea();
27 32
 
28
-        Button btnSubmit = new Button("Set Account ID");
33
+        Button btnSubmit = new Button("Enter");
29 34
         btnSubmit.setOnAction(e -> {
30 35
             int id = Integer.parseInt(field.getText());
31 36
             cashMachine.login(id);
32 37
 
33 38
             areaInfo.setText(cashMachine.toString());
34 39
         });
40
+/*
41
+        //Make Button Do something.
42
+        Button btnNewAccount = new Button("Setup New Account");
43
+        btnSubmit.setOnAction(e -> {
44
+            int id = Integer.parseInt(field.getText());
45
+            cashMachine.login(id);
46
+
47
+        });
35 48
 
49
+        //Make Button Do something.
50
+        Button btnForgotAccountNumber = new Button("Forgot Account Number");
51
+        btnSubmit.setOnAction(e -> {
52
+            int id = Integer.parseInt(field.getText());
53
+            cashMachine.login(id);
54
+
55
+        });
56
+*/
36 57
         Button btnDeposit = new Button("Deposit");
37 58
         btnDeposit.setOnAction(e -> {
38
-            int amount = Integer.parseInt(field.getText());
59
+            int amount = Integer.parseInt(field2.getText());
39 60
             cashMachine.deposit(amount);
40 61
 
41 62
             areaInfo.setText(cashMachine.toString());
@@ -43,36 +64,59 @@ public class CashMachineApp extends Application {
43 64
 
44 65
         Button btnWithdraw = new Button("Withdraw");
45 66
         btnWithdraw.setOnAction(e -> {
46
-            int amount = Integer.parseInt(field.getText());
67
+            int amount = Integer.parseInt(field2.getText());
47 68
             cashMachine.withdraw(amount);
48 69
 
49 70
             areaInfo.setText(cashMachine.toString());
50 71
         });
51 72
 
52
-        Button btnExit = new Button("Exit");
73
+        Button btnExit = new Button("LogOut");
53 74
         btnExit.setOnAction(e -> {
54 75
             cashMachine.exit();
55
-
56
-            areaInfo.setText(cashMachine.toString());
76
+            field.clear();
77
+            field2.clear();
78
+            areaInfo.clear();
57 79
         });
58 80
 
59 81
         FlowPane flowpane = new FlowPane();
60 82
 
61 83
         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);
84
+        /*
85
+        flowpane.getChildren().add(btnNewAccount);
86
+        flowpane.getChildren().add(btnForgotAccountNumber);
87
+        */
88
+
89
+        FlowPane flowpane2 = new FlowPane();
90
+
91
+        flowpane2.getChildren().add(btnDeposit);
92
+        flowpane2.getChildren().add(btnWithdraw);
93
+        flowpane2.getChildren().add(btnExit);
94
+        Label fieldLabel2 = new Label("Amount:");
95
+        Label accountInfo2 = new Label("Account Info:");
96
+
97
+        field.setStyle("-fx-background-color: beige;");
98
+        field2.setStyle("-fx-background-color: beige;");
99
+        Label fieldLabel = new Label("Account Number:");
100
+        vbox.getChildren().addAll(fieldLabel, field, flowpane, fieldLabel2, field2, flowpane2, accountInfo2, areaInfo);
101
+
102
+
103
+
66 104
         return vbox;
105
+
106
+
67 107
     }
68 108
 
69 109
     @Override
70 110
     public void start(Stage stage) throws Exception {
111
+        stage.setTitle("ZipCloud Bank");
71 112
         stage.setScene(new Scene(createContent()));
72 113
         stage.show();
114
+
73 115
     }
74 116
 
75 117
     public static void main(String[] args) {
76 118
         launch(args);
77 119
     }
120
+
121
+
78 122
 }

+ 29
- 1
src/main/java/rocks/zipcode/atm/bank/Bank.java Просмотреть файл

@@ -11,6 +11,9 @@ import java.util.Map;
11 11
 public class Bank {
12 12
 
13 13
     private Map<Integer, Account> accounts = new HashMap<>();
14
+    //private static int nextId = 1000;
15
+
16
+    /* Add options for user to create an account and have a number issued to them. */
14 17
 
15 18
     public Bank() {
16 19
         accounts.put(1000, new BasicAccount(new AccountData(
@@ -22,13 +25,38 @@ public class Bank {
22 25
         )));
23 26
     }
24 27
 
28
+/*How to use this???
29
+    public Bank(String name, String email, int initialBalance, boolean typeOfAccount) {
30
+        nextId++;
31
+        if (!typeOfAccount) {
32
+        accounts.put(nextId, new BasicAccount(new AccountData(
33
+                nextId, name, email, initialBalance
34
+        ))); } else {
35
+            accounts.put(nextId, new PremiumAccount(new AccountData(
36
+                    nextId, name, email, initialBalance
37
+            )));
38
+        }
39
+
40
+    }
41
+
42
+*/
25 43
     public ActionResult<AccountData> getAccountById(int id) {
26 44
         Account account = accounts.get(id);
27 45
 
28 46
         if (account != null) {
29 47
             return ActionResult.success(account.getAccountData());
30 48
         } else {
31
-            return ActionResult.fail("No account with id: " + id + "\nTry account 1000 or 2000");
49
+            return ActionResult.fail("No account with id: " + id);
50
+        }
51
+    }
52
+
53
+    public ActionResult<AccountData> getByName(int id) {
54
+        Account account = accounts.get(id);
55
+
56
+        if (account != null) {
57
+            return ActionResult.success(account.getAccountData());
58
+        } else {
59
+            return ActionResult.fail("No account with id: " + id);
32 60
         }
33 61
     }
34 62