#10 CashMachine

Open
pchai7 wants to merge 1 commits from pchai7/CashMachine:master into master

+ 10
- 0
src/main/java/rocks/zipcode/atm/CashMachine.java View File

46
             );
46
             );
47
         }
47
         }
48
     }
48
     }
49
+    public void balance(int amount) {
50
+        if (accountData != null) {
51
+            tryCall(
52
+                    () -> bank.balance(accountData, amount),
53
+                    update
54
+            );
55
+        }
56
+    }
49
 
57
 
50
     public void exit() {
58
     public void exit() {
51
         if (accountData != null) {
59
         if (accountData != null) {
72
             System.out.println("Error: " + e.getMessage());
80
             System.out.println("Error: " + e.getMessage());
73
         }
81
         }
74
     }
82
     }
83
+
84
+
75
 }
85
 }

+ 20
- 2
src/main/java/rocks/zipcode/atm/CashMachineApp.java View File

1
 package rocks.zipcode.atm;
1
 package rocks.zipcode.atm;
2
 
2
 
3
+import javafx.scene.layout.HBox;
3
 import rocks.zipcode.atm.bank.Bank;
4
 import rocks.zipcode.atm.bank.Bank;
4
 import javafx.application.Application;
5
 import javafx.application.Application;
5
 import javafx.scene.Parent;
6
 import javafx.scene.Parent;
19
     private TextField field = new TextField();
20
     private TextField field = new TextField();
20
     private CashMachine cashMachine = new CashMachine(new Bank());
21
     private CashMachine cashMachine = new CashMachine(new Bank());
21
 
22
 
23
+
22
     private Parent createContent() {
24
     private Parent createContent() {
23
         VBox vbox = new VBox(10);
25
         VBox vbox = new VBox(10);
24
-        vbox.setPrefSize(600, 600);
26
+        vbox.setPrefSize(800, 600);
25
 
27
 
26
         TextArea areaInfo = new TextArea();
28
         TextArea areaInfo = new TextArea();
27
 
29
 
28
-        Button btnSubmit = new Button("Set Account ID");
30
+        Button btnSubmit = new Button("Account ID");
31
+        btnSubmit.setStyle("-fx-border-color: #0000ff; -fx-border-width: 5px;");
29
         btnSubmit.setOnAction(e -> {
32
         btnSubmit.setOnAction(e -> {
30
             int id = Integer.parseInt(field.getText());
33
             int id = Integer.parseInt(field.getText());
31
             cashMachine.login(id);
34
             cashMachine.login(id);
34
         });
37
         });
35
 
38
 
36
         Button btnDeposit = new Button("Deposit");
39
         Button btnDeposit = new Button("Deposit");
40
+        btnDeposit.setStyle("-fx-border-color: #0000ff; -fx-border-width: 5px;");
37
         btnDeposit.setOnAction(e -> {
41
         btnDeposit.setOnAction(e -> {
38
             int amount = Integer.parseInt(field.getText());
42
             int amount = Integer.parseInt(field.getText());
39
             cashMachine.deposit(amount);
43
             cashMachine.deposit(amount);
42
         });
46
         });
43
 
47
 
44
         Button btnWithdraw = new Button("Withdraw");
48
         Button btnWithdraw = new Button("Withdraw");
49
+        btnWithdraw.setStyle("-fx-border-color: #0000ff; -fx-border-width: 5px;");
45
         btnWithdraw.setOnAction(e -> {
50
         btnWithdraw.setOnAction(e -> {
46
             int amount = Integer.parseInt(field.getText());
51
             int amount = Integer.parseInt(field.getText());
47
             cashMachine.withdraw(amount);
52
             cashMachine.withdraw(amount);
49
             areaInfo.setText(cashMachine.toString());
54
             areaInfo.setText(cashMachine.toString());
50
         });
55
         });
51
 
56
 
57
+        Button btnBalance = new Button("Balance");
58
+        btnBalance.setStyle("-fx-border-color: #0000ff; -fx-border-width: 5px;");
59
+        btnBalance.setOnAction(e -> {
60
+            int amount = Integer.parseInt(field.getText());
61
+            cashMachine.balance(amount);
62
+
63
+            areaInfo.setText(cashMachine.toString());
64
+        });
65
+
52
         Button btnExit = new Button("Exit");
66
         Button btnExit = new Button("Exit");
67
+        btnExit.setStyle("-fx-border-color: #0000ff; -fx-border-width: 5px;");
53
         btnExit.setOnAction(e -> {
68
         btnExit.setOnAction(e -> {
54
             cashMachine.exit();
69
             cashMachine.exit();
55
 
70
 
68
 
83
 
69
     @Override
84
     @Override
70
     public void start(Stage stage) throws Exception {
85
     public void start(Stage stage) throws Exception {
86
+        stage.setTitle("Welcome to ZipCloudBank");
87
+
71
         stage.setScene(new Scene(createContent()));
88
         stage.setScene(new Scene(createContent()));
72
         stage.show();
89
         stage.show();
90
+
73
     }
91
     }
74
 
92
 
75
     public static void main(String[] args) {
93
     public static void main(String[] args) {

+ 5
- 0
src/main/java/rocks/zipcode/atm/bank/Account.java View File

40
         accountData = new AccountData(accountData.getId(), accountData.getName(), accountData.getEmail(),
40
         accountData = new AccountData(accountData.getId(), accountData.getName(), accountData.getEmail(),
41
                 newBalance);
41
                 newBalance);
42
     }
42
     }
43
+
44
+
45
+    public void balance(int amount) {
46
+
47
+    }
43
 }
48
 }

+ 7
- 0
src/main/java/rocks/zipcode/atm/bank/Bank.java View File

49
             return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
49
             return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
50
         }
50
         }
51
     }
51
     }
52
+
53
+    public <T> ActionResult<T> balance(AccountData accountData, int amount) {
54
+        Account account = accounts.get(accountData.getId());
55
+        account.balance(amount);
56
+
57
+        return (ActionResult<T>) ActionResult.success(account.getAccountData());
58
+    }
52
 }
59
 }