#4 completed

Abierta
yesoda desea fusionar 2 commits de yesoda/CashMachine:master en master

BIN
.DS_Store Ver fichero


BIN
src/.DS_Store Ver fichero


BIN
src/main/.DS_Store Ver fichero


BIN
src/main/java/.DS_Store Ver fichero


BIN
src/main/java/rocks/.DS_Store Ver fichero


BIN
src/main/java/rocks/zipcode/.DS_Store Ver fichero


+ 0
- 78
src/main/java/rocks/zipcode/atm/CashMachineApp.java Ver fichero

@@ -1,78 +0,0 @@
1
-package rocks.zipcode.atm;
2
-
3
-import rocks.zipcode.atm.bank.Bank;
4
-import javafx.application.Application;
5
-import javafx.scene.Parent;
6
-import javafx.scene.Scene;
7
-import javafx.scene.control.Button;
8
-import javafx.scene.control.TextArea;
9
-import javafx.scene.control.TextField;
10
-import javafx.scene.layout.VBox;
11
-import javafx.stage.Stage;
12
-import javafx.scene.layout.FlowPane;
13
-
14
-/**
15
- * @author ZipCodeWilmington
16
- */
17
-public class CashMachineApp extends Application {
18
-
19
-    private TextField field = new TextField();
20
-    private CashMachine cashMachine = new CashMachine(new Bank());
21
-
22
-    private Parent createContent() {
23
-        VBox vbox = new VBox(10);
24
-        vbox.setPrefSize(600, 600);
25
-
26
-        TextArea areaInfo = new TextArea();
27
-
28
-        Button btnSubmit = new Button("Set Account ID");
29
-        btnSubmit.setOnAction(e -> {
30
-            int id = Integer.parseInt(field.getText());
31
-            cashMachine.login(id);
32
-
33
-            areaInfo.setText(cashMachine.toString());
34
-        });
35
-
36
-        Button btnDeposit = new Button("Deposit");
37
-        btnDeposit.setOnAction(e -> {
38
-            int amount = Integer.parseInt(field.getText());
39
-            cashMachine.deposit(amount);
40
-
41
-            areaInfo.setText(cashMachine.toString());
42
-        });
43
-
44
-        Button btnWithdraw = new Button("Withdraw");
45
-        btnWithdraw.setOnAction(e -> {
46
-            int amount = Integer.parseInt(field.getText());
47
-            cashMachine.withdraw(amount);
48
-
49
-            areaInfo.setText(cashMachine.toString());
50
-        });
51
-
52
-        Button btnExit = new Button("Exit");
53
-        btnExit.setOnAction(e -> {
54
-            cashMachine.exit();
55
-
56
-            areaInfo.setText(cashMachine.toString());
57
-        });
58
-
59
-        FlowPane flowpane = new FlowPane();
60
-
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;
67
-    }
68
-
69
-    @Override
70
-    public void start(Stage stage) throws Exception {
71
-        stage.setScene(new Scene(createContent()));
72
-        stage.show();
73
-    }
74
-
75
-    public static void main(String[] args) {
76
-        launch(args);
77
-    }
78
-}

src/main/java/rocks/zipcode/atm/ActionResult.java → src/main/java/rocks/zipcode/yesoda/ActionResult.java Ver fichero

@@ -1,4 +1,4 @@
1
-package rocks.zipcode.atm;
1
+package rocks.zipcode.yesoda;
2 2
 
3 3
 /**
4 4
  * @author ZipCodeWilmington

src/main/java/rocks/zipcode/atm/CashMachine.java → src/main/java/rocks/zipcode/yesoda/CashMachine.java Ver fichero

@@ -1,7 +1,7 @@
1
-package rocks.zipcode.atm;
1
+package rocks.zipcode.yesoda;
2 2
 
3
-import rocks.zipcode.atm.bank.AccountData;
4
-import rocks.zipcode.atm.bank.Bank;
3
+import rocks.zipcode.yesoda.bank.AccountData;
4
+import rocks.zipcode.yesoda.bank.Bank;
5 5
 
6 6
 import java.util.function.Consumer;
7 7
 import java.util.function.Supplier;
@@ -55,7 +55,7 @@ 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() : new String ("1");
59 59
     }
60 60
 
61 61
     private <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {

+ 165
- 0
src/main/java/rocks/zipcode/yesoda/CashMachineApp.java Ver fichero

@@ -0,0 +1,165 @@
1
+package rocks.zipcode.yesoda;
2
+
3
+
4
+import javafx.application.Application;
5
+import javafx.geometry.Insets;
6
+import javafx.geometry.Pos;
7
+import javafx.scene.Parent;
8
+import javafx.scene.Scene;
9
+import javafx.scene.control.*;
10
+import javafx.scene.layout.VBox;
11
+import javafx.stage.Stage;
12
+import javafx.scene.layout.FlowPane;
13
+import rocks.zipcode.yesoda.bank.Bank;
14
+
15
+/**
16
+ * @author ZipCodeWilmington
17
+ */
18
+public class CashMachineApp extends Application {
19
+
20
+    private TextField fieldID = new TextField();
21
+    private TextField fieldWithdraw = new TextField();
22
+    private CashMachine cashMachine = new CashMachine(new Bank());
23
+    Button btnDeposit = new Button();
24
+    Button btnWithdraw = new Button();
25
+
26
+    private Parent createContent() {
27
+        VBox vbox = new VBox(10);
28
+        Label mainLabel = new Label();
29
+        mainLabel.setText("Welcome to ZIP CODE \n CASH MACHINE");
30
+        vbox.setPrefSize(600, 600);
31
+        String strTemp;
32
+
33
+        TextArea areaInfo = new TextArea();
34
+
35
+        Button btnSubmit = new Button("Enter Your AccountID");
36
+        btnSubmit.setOnAction(e -> {
37
+
38
+            int id = Integer.parseInt(fieldID.getText());
39
+            cashMachine.login(id);
40
+
41
+            if (cashMachine.toString().toString().equalsIgnoreCase("1")) {
42
+                showAlertWithHeaderText("ERROR","" ,"Enter a valid Account number - 1000 or 2000 ");
43
+            } else {
44
+                areaInfo.setText(cashMachine.toString());
45
+                onValidIDButtonIdClick(btnSubmit);
46
+            }
47
+        });
48
+
49
+        Button btnParentExit = new Button("Exit");
50
+        btnParentExit.setOnAction(e -> {
51
+            cashMachine.exit();
52
+
53
+            //areaInfo.setText(cashMachine.toString());
54
+        });
55
+
56
+        FlowPane flowpane = new FlowPane();
57
+
58
+        mainLabel.setLayoutX(100);
59
+        mainLabel.setLayoutY(100);
60
+        vbox.setAlignment(Pos.TOP_CENTER);
61
+        fieldID.setMaxSize( 200, 20);
62
+        vbox.getChildren().addAll(mainLabel, btnSubmit, fieldID, flowpane, btnParentExit);
63
+        return vbox;
64
+    }
65
+
66
+
67
+    public void onValidIDButtonIdClick(Button btnSubmit) {
68
+        FlowPane flow = new FlowPane();
69
+        Scene secondScene = new Scene(flow, 600, 600);
70
+        Stage secondStage = new Stage();
71
+
72
+        TextField fieldDeposit = new TextField();
73
+        flow.setAlignment(Pos.TOP_LEFT);
74
+        //fieldDeposit.setText("Enter the Amount to Deposit - ");
75
+        flow.setAlignment(Pos.TOP_RIGHT);
76
+        flow.getChildren().add(fieldDeposit);
77
+        Button btnDeposit = new Button("Deposit");
78
+        flow.getChildren().add(btnDeposit);
79
+        TextField fieldWithDraw = new TextField();
80
+        flow.getChildren().add(fieldWithDraw);
81
+        Button btnWithdraw = new Button("WithDraw");
82
+        flow.getChildren().add(btnWithdraw);
83
+        TextArea areaInfo = new TextArea();
84
+        Button btnExit = exitButtonDisplay(secondStage );
85
+        flow.setPadding(new Insets(10, 10, 10, 10));
86
+        flow.setStyle("-fx-background-color: DAE6F3;");
87
+        flow.setHgap(10);
88
+        flow.getChildren().add(btnExit );
89
+        flow.getChildren().add (areaInfo);
90
+        secondStage.setScene(secondScene); // set the scene
91
+        secondStage.setTitle(" Please select the Bank Operation you want to perform ");
92
+        secondStage.show();
93
+        // close the first stage (Window)
94
+
95
+        btnDeposit.setOnAction(e -> {
96
+            int amount = Integer.parseInt(fieldDeposit.getText());
97
+            cashMachine.deposit(amount);
98
+
99
+            showAlertWithHeaderText("Deposit Success","" ,"Deposited Amount Successfully");
100
+            areaInfo.setPrefRowCount(8);
101
+            areaInfo.setText("Amount deposited now - " + amount + " \n ----Account Summary ----  \n" + cashMachine.toString());
102
+            areaInfo.setText(cashMachine.toString());
103
+            //cashMachine.toString();
104
+        }) ;
105
+
106
+        btnWithdraw.setOnAction(e -> {
107
+            int amount = Integer.parseInt(fieldWithDraw .getText());
108
+            cashMachine.withdraw(amount);
109
+            showAlertWithHeaderText("Withdraw","" ,"Withdraw Amount Successfully");
110
+            areaInfo.setText(cashMachine.toString());
111
+        });
112
+
113
+
114
+
115
+
116
+    }
117
+
118
+   /* public void onDepositButtonClick()
119
+    {
120
+        Button btnDeposit = new Button("Deposit");
121
+        btnDeposit.setOnAction(e -> {
122
+            int amount = Integer.parseInt(fieldID.getText());
123
+            cashMachine.deposit(amount);
124
+
125
+           // areaInfo.setText(cashMachine.toString());
126
+        });
127
+    }*/
128
+
129
+    public Button exitButtonDisplay(Stage stage) {
130
+
131
+        Button btnExit = new Button("Exit");
132
+        btnExit.setOnAction(e ->
133
+
134
+        {
135
+            cashMachine.exit();
136
+            stage.close();
137
+
138
+            //areaInfo.setText(cashMachine.toString());
139
+        });
140
+        return btnExit;
141
+
142
+
143
+    }
144
+
145
+        private void showAlertWithHeaderText(String title,String headertxt,String content ) {
146
+            Alert alert = new Alert(Alert.AlertType.INFORMATION);
147
+            alert.setTitle(title);
148
+            alert.setHeaderText(headertxt);
149
+            alert.setContentText(content);
150
+
151
+            alert.showAndWait();
152
+        }
153
+
154
+
155
+    @Override
156
+    public void start(Stage stage) throws Exception {
157
+        stage.setScene(new Scene(createContent()));
158
+        stage.show();
159
+        //stage.close();
160
+    }
161
+
162
+    public static void main(String[] args) {
163
+        launch(args);
164
+    }
165
+}

src/main/java/rocks/zipcode/atm/bank/Account.java → src/main/java/rocks/zipcode/yesoda/bank/Account.java Ver fichero

@@ -1,4 +1,4 @@
1
-package rocks.zipcode.atm.bank;
1
+package rocks.zipcode.yesoda.bank;
2 2
 
3 3
 /**
4 4
  * @author ZipCodeWilmington

src/main/java/rocks/zipcode/atm/bank/AccountData.java → src/main/java/rocks/zipcode/yesoda/bank/AccountData.java Ver fichero

@@ -1,4 +1,4 @@
1
-package rocks.zipcode.atm.bank;
1
+package rocks.zipcode.yesoda.bank;
2 2
 
3 3
 /**
4 4
  * @author ZipCodeWilmington
@@ -16,6 +16,7 @@ public final class AccountData {
16 16
         this.name = name;
17 17
         this.email = email;
18 18
         this.balance = balance;
19
+
19 20
     }
20 21
 
21 22
     public int getId() {

src/main/java/rocks/zipcode/atm/bank/Bank.java → src/main/java/rocks/zipcode/yesoda/bank/Bank.java Ver fichero

@@ -1,6 +1,6 @@
1
-package rocks.zipcode.atm.bank;
1
+package rocks.zipcode.yesoda.bank;
2 2
 
3
-import rocks.zipcode.atm.ActionResult;
3
+import rocks.zipcode.yesoda.ActionResult;
4 4
 
5 5
 import java.util.HashMap;
6 6
 import java.util.Map;
@@ -17,6 +17,7 @@ public class Bank {
17 17
                 1000, "Example 1", "example1@gmail.com", 500
18 18
         )));
19 19
 
20
+
20 21
         accounts.put(2000, new PremiumAccount(new AccountData(
21 22
                 2000, "Example 2", "example2@gmail.com", 200
22 23
         )));
@@ -28,7 +29,7 @@ public class Bank {
28 29
         if (account != null) {
29 30
             return ActionResult.success(account.getAccountData());
30 31
         } else {
31
-            return ActionResult.fail("No account with id: " + id + "\nTry account 1000 or 2000");
32
+            return ActionResult.fail("No account with id: " + id + "Try account 1000 or 2000");
32 33
         }
33 34
     }
34 35
 

src/main/java/rocks/zipcode/atm/bank/BasicAccount.java → src/main/java/rocks/zipcode/yesoda/bank/BasicAccount.java Ver fichero

@@ -1,4 +1,4 @@
1
-package rocks.zipcode.atm.bank;
1
+package rocks.zipcode.yesoda.bank;
2 2
 
3 3
 /**
4 4
  * @author ZipCodeWilmington

src/main/java/rocks/zipcode/atm/bank/PremiumAccount.java → src/main/java/rocks/zipcode/yesoda/bank/PremiumAccount.java Ver fichero

@@ -1,4 +1,4 @@
1
-package rocks.zipcode.atm.bank;
1
+package rocks.zipcode.yesoda.bank;
2 2
 
3 3
 /**
4 4
  * @author ZipCodeWilmington