Bläddra i källkod

Working, new account unifnished

Demetrius Murray 6 år sedan
förälder
incheckning
1dfed2dece

+ 11
- 0
src/main/java/rocks/zipcode/atm/CashMachine.java Visa fil

@@ -1,5 +1,6 @@
1 1
 package rocks.zipcode.atm;
2 2
 
3
+import rocks.zipcode.atm.bank.Account;
3 4
 import rocks.zipcode.atm.bank.AccountData;
4 5
 import rocks.zipcode.atm.bank.Bank;
5 6
 
@@ -74,6 +75,16 @@ public class CashMachine {
74 75
         return bank.listAccounts();
75 76
     }
76 77
 
78
+    public int newBasicAccount(String name, String email, double balance) {
79
+        bank.addBasicAccount(name,email,balance);
80
+        return bank.newId();
81
+    }
82
+
83
+    public int newPremiumAccount(String name, String email, double balance) {
84
+        bank.addPremiumAccount(name,email,balance);
85
+        return bank.newId();
86
+    }
87
+
77 88
     @Override
78 89
     public String toString() {
79 90
         return accountData != null ? accountData.toString() : "Try account 1000 or 2000 and click submit.";

+ 0
- 114
src/main/java/rocks/zipcode/atm/CashMachine2.java Visa fil

@@ -1,114 +0,0 @@
1
-package rocks.zipcode.atm;
2
-
3
-import javafx.application.Application;
4
-import javafx.geometry.Insets;
5
-import javafx.scene.Scene;
6
-import javafx.scene.control.Button;
7
-import javafx.scene.control.TextField;
8
-import javafx.scene.layout.FlowPane;
9
-import javafx.scene.layout.GridPane;
10
-import javafx.scene.layout.VBox;
11
-import javafx.scene.paint.Color;
12
-import javafx.scene.text.Text;
13
-import javafx.stage.Stage;
14
-import rocks.zipcode.atm.bank.Bank;
15
-
16
-public class CashMachine2 extends Application {
17
-    CashMachine cashMachine = new CashMachine(new Bank());
18
-    Text account = new Text();
19
-    Text name = new Text();
20
-    Text email = new Text();
21
-    Text balance = new Text();
22
-    Button btnDeposit = new Button("Deposit");
23
-    Button btnWithdraw = new Button("Withdraw");
24
-    Button btnExit = new Button("Logout");
25
-    Button btnSubmit = new Button("Login");
26
-    Button btnClose = new Button("Exit");
27
-    FlowPane fp = new FlowPane();
28
-    FlowPane fp2 = new FlowPane();
29
-    GridPane gp2 = new GridPane();
30
-    VBox vb = new VBox();
31
-    VBox vb2 = new VBox();
32
-    private TextField field = new TextField();
33
-    private TextField field2 = new TextField();
34
-
35
-    public static void main(String[] args) {
36
-        launch(args);
37
-    }
38
-
39
-    @Override
40
-    public void start(Stage primaryStage) {
41
-        field.setFocusTraversable(false);
42
-        field.setPromptText("Enter Account ID");
43
-
44
-        Scene scene1 = new Scene(vb,300,250, Color.BURLYWOOD);
45
-        Scene scene2 = new Scene(vb2,300,250, Color.BURLYWOOD);
46
-
47
-        btnSubmit.setOnAction(e -> {
48
-            int id = Integer.parseInt(field.getText());
49
-            cashMachine.login(id);
50
-            primaryStage.setScene(scene2);
51
-//            account.setText(cashMachine.accountIdToString());
52
-//            name.setText(cashMachine.nameToString());
53
-//            email.setText(cashMachine.emailToString());
54
-//            balance.setText(cashMachine.balanceToString());
55
-//            btnDeposit.setVisible(true);
56
-//            btnWithdraw.setVisible(true);
57
-//            btnExit.setVisible(true);
58
-            //menuBar.setVisible(true);
59
-        });
60
-
61
-        btnDeposit.setOnAction(e -> {
62
-            double amount = Integer.parseInt(field2.getText());
63
-            cashMachine.deposit(amount);
64
-
65
-            account.setText(cashMachine.accountIdToString());
66
-            name.setText(cashMachine.nameToString());
67
-            email.setText(cashMachine.emailToString());
68
-            balance.setText(cashMachine.balanceToString());
69
-        });
70
-
71
-
72
-        btnWithdraw.setOnAction(e -> {
73
-            double amount = Integer.parseInt(field2.getText());
74
-            cashMachine.withdraw(amount);
75
-
76
-            account.setText(cashMachine.accountIdToString());
77
-            name.setText(cashMachine.nameToString());
78
-            email.setText(cashMachine.emailToString());
79
-            balance.setText(cashMachine.balanceToString());
80
-        });
81
-
82
-        btnExit.setOnAction(e -> {
83
-            cashMachine.exit();
84
-            primaryStage.setScene(scene1);
85
-        });
86
-
87
-        btnClose.setOnAction(e -> {
88
-            System.exit(0);
89
-        }); //add alert box to ask Are you sure??
90
-
91
-        gp2.setVgap(.5);
92
-        gp2.setPadding(new Insets(25,25,25,25));
93
-        gp2.setOpacity(50);
94
-        gp2.setStyle(" -fx-opacity: 10; -fx-padding: 2; -fx-border-color: dimgrey; -fx-border-style: solid; -fx-border-width: 2; -fx-vgap: 5");
95
-        //scene1 items
96
-        fp.getChildren().addAll(btnSubmit,btnExit);
97
-        vb.getChildren().addAll(field,fp);
98
-        //scene2items
99
-        fp2.getChildren().addAll(btnDeposit,btnWithdraw,btnExit);
100
-        gp2.add(account,1,0);
101
-        gp2.add(name,1,1);
102
-        gp2.add(email,1,2);
103
-        gp2.add(balance,1,3);
104
-        vb2.getChildren().addAll(field2,fp2,gp2);
105
-
106
-
107
-//        fp.getChildren().add(menuBar);
108
-
109
-
110
-        primaryStage.setTitle("Primary");
111
-        primaryStage.setScene(scene1);
112
-        primaryStage.show();
113
-    }
114
-}

+ 179
- 138
src/main/java/rocks/zipcode/atm/CashMachineApp.java Visa fil

@@ -1,138 +1,179 @@
1
-//package rocks.zipcode.atm;
2
-//
3
-//import javafx.geometry.Insets;
4
-//import javafx.geometry.Pos;
5
-//import javafx.scene.control.*;
6
-//import javafx.scene.layout.GridPane;
7
-//import javafx.scene.text.Text;
8
-//import rocks.zipcode.atm.bank.Bank;
9
-//import javafx.application.Application;
10
-//import javafx.scene.Parent;
11
-//import javafx.scene.Scene;
12
-//import javafx.scene.layout.VBox;
13
-//import javafx.stage.Stage;
14
-//import javafx.scene.layout.FlowPane;
15
-//
16
-//import java.util.ArrayList;
17
-//
18
-///**
19
-// * @author ZipCodeWilmington
20
-// */
21
-//public class CashMachineApp extends Application {
22
-//
23
-//    private TextField field = new TextField();
24
-//    private CashMachine cashMachine = new CashMachine(new Bank());
25
-//
26
-//    private Parent createContent() {
27
-//        field.setFocusTraversable(false);
28
-//        field.setPromptText("Enter Account ID");
29
-//        FlowPane flowpane = new FlowPane();
30
-//        VBox vbox = new VBox(10);
31
-//        vbox.setPrefSize(600, 600);
32
-//
33
-//        TextArea areaInfo = new TextArea();
34
-//
35
-//        GridPane gridPane = new GridPane();
36
-//        gridPane.setAlignment(Pos.CENTER_LEFT);
37
-//        gridPane.setVgap(5);
38
-//        gridPane.setHgap(5);
39
-//        Text account = new Text();
40
-//        Text name = new Text();
41
-//        Text email = new Text();
42
-//        Text balance = new Text();
43
-//
44
-//
45
-//        MenuBar menuBar = new MenuBar();
46
-//
47
-//        Button btnDeposit = new Button("Deposit");
48
-//        btnDeposit.setOnAction(e -> {
49
-//            int amount = Integer.parseInt(field.getText());
50
-//            cashMachine.deposit(amount);
51
-//
52
-//            account.setText(cashMachine.accountIdToString());
53
-//            name.setText(cashMachine.nameToString());
54
-//            email.setText(cashMachine.emailToString());
55
-//            balance.setText(cashMachine.balanceToString());
56
-//        });
57
-//
58
-//        Button btnWithdraw = new Button("Withdraw");
59
-//        btnWithdraw.setOnAction(e -> {
60
-//            int amount = Integer.parseInt(field.getText());
61
-//            cashMachine.withdraw(amount);
62
-//
63
-//            account.setText(cashMachine.accountIdToString());
64
-//            name.setText(cashMachine.nameToString());
65
-//            email.setText(cashMachine.emailToString());
66
-//            balance.setText(cashMachine.balanceToString());
67
-//        });
68
-//
69
-//        Button btnExit = new Button("Exit");
70
-//        btnExit.setOnAction(e -> {
71
-//            cashMachine.exit();
72
-//            account.setText(cashMachine.accountIdToString());
73
-//            name.setText(cashMachine.nameToString());
74
-//            email.setText(cashMachine.emailToString());
75
-//            balance.setText(cashMachine.balanceToString());
76
-//        });
77
-//
78
-//        Button btnSubmit = new Button("Login");
79
-//        btnSubmit.setOnAction(e -> {
80
-//            int id = Integer.parseInt(field.getText());
81
-//            cashMachine.login(id);
82
-//            account.setText(cashMachine.accountIdToString());
83
-//            name.setText(cashMachine.nameToString());
84
-//            email.setText(cashMachine.emailToString());
85
-//            balance.setText(cashMachine.balanceToString());
86
-//            btnDeposit.setVisible(true);
87
-//            btnWithdraw.setVisible(true);
88
-//            btnExit.setVisible(true);
89
-//            menuBar.setVisible(true);
90
-//
91
-//
92
-//        });
93
-//
94
-//        btnDeposit.setVisible(false);
95
-//        btnWithdraw.setVisible(false);
96
-//        btnExit.setVisible(false);
97
-//        menuBar.setVisible(false);
98
-//
99
-//        Menu accountMenu = new Menu("All Accounts");
100
-//
101
-//        flowpane.getChildren().add(btnSubmit);
102
-//        flowpane.getChildren().add(btnDeposit);
103
-//        flowpane.getChildren().add(btnWithdraw);
104
-//        flowpane.getChildren().add(btnExit);
105
-//        flowpane.getChildren().add(menuBar);
106
-//        menuBar.getMenus().add(accountMenu);
107
-//
108
-//        ArrayList<String> accountList = cashMachine.listAccounts();
109
-//        for(String acct : accountList){
110
-//            MenuItem newItem = new MenuItem(acct);
111
-//            newItem.setOnAction(e -> {
112
-//                field.clear();
113
-//                field.setPromptText("Enter Id and click \"Login\"");
114
-//            });
115
-//
116
-//            accountMenu.getItems().add(newItem);
117
-//
118
-//        }
119
-//
120
-//        gridPane.setPadding(new Insets(25,25,25,25));
121
-//        gridPane.add(account,0,1);
122
-//        gridPane.add(name,0,2);
123
-//        gridPane.add(email,0,3);
124
-//        gridPane.add(balance,0,4);
125
-//        vbox.getChildren().addAll(field, flowpane, gridPane);
126
-//        return vbox;
127
-//    }
128
-//
129
-//    @Override
130
-//    public void start(Stage stage) throws Exception {
131
-//        stage.setScene(new Scene(createContent()));
132
-//        stage.show();
133
-//    }
134
-//
135
-//    public static void main(String[] args) {
136
-//        launch(args);
137
-//    }
138
-//}
1
+package rocks.zipcode.atm;
2
+
3
+import javafx.application.Application;
4
+import javafx.geometry.Insets;
5
+import javafx.geometry.Pos;
6
+import javafx.scene.Scene;
7
+import javafx.scene.control.*;
8
+import javafx.scene.layout.FlowPane;
9
+import javafx.scene.layout.GridPane;
10
+import javafx.scene.layout.VBox;
11
+import javafx.scene.paint.Color;
12
+import javafx.scene.text.Font;
13
+import javafx.scene.text.Text;
14
+import javafx.stage.Stage;
15
+import rocks.zipcode.atm.bank.Bank;
16
+
17
+import java.util.ArrayList;
18
+
19
+public class CashMachineApp extends Application {
20
+    CashMachine cashMachine = new CashMachine(new Bank());
21
+    Text account = new Text();
22
+    Text name = new Text();
23
+    Text email = new Text();
24
+    Text balance = new Text();
25
+    Button btnDeposit = new Button("Deposit");
26
+    Button btnWithdraw = new Button("Withdraw");
27
+    Button btnExit = new Button("Logout");
28
+    Button btnSubmit = new Button("Login");
29
+    Button btnClose = new Button("Exit");
30
+    Button btnNewAccount = new Button("New Account");
31
+    TextField name1 = new TextField("Name");
32
+    TextField email1 = new TextField("Email");
33
+    TextField balance1 = new TextField("Balance");
34
+    RadioButton basicAcct = new RadioButton("Basic Account");
35
+    RadioButton premAcct = new RadioButton("Premium Account");
36
+    Button btnSubmit2 = new Button("Create Account");
37
+
38
+    FlowPane fp = new FlowPane();
39
+    FlowPane fp2 = new FlowPane();
40
+    GridPane gp2 = new GridPane();
41
+    VBox vb3 = new VBox();
42
+    VBox vb = new VBox();
43
+    VBox vb2 = new VBox();
44
+    private TextField field = new TextField();
45
+    private TextField field2 = new TextField();
46
+
47
+    public static void main(String[] args) {
48
+        launch(args);
49
+    }
50
+
51
+    @Override
52
+    public void start(Stage primaryStage) {
53
+        field.setFocusTraversable(false);
54
+        field.setPromptText("Enter Account ID");
55
+        field.setPadding(new Insets(5,0,5,0));
56
+        field.setMaxWidth(250);
57
+
58
+        Scene scene1 = new Scene(vb,300,250, Color.BURLYWOOD);
59
+        Scene scene2 = new Scene(vb2,300,250, Color.BURLYWOOD);
60
+        Scene scene3 = new Scene(vb3,300,250, Color.BURLYWOOD);
61
+
62
+        btnSubmit.setOnAction(e -> {
63
+            field.clear();
64
+            int id = Integer.parseInt(field.getText());
65
+            cashMachine.login(id);
66
+            primaryStage.setScene(scene2);
67
+        });
68
+
69
+        btnDeposit.setOnAction(e -> {
70
+            double amount = Integer.parseInt(field2.getText());
71
+            cashMachine.deposit(amount);
72
+
73
+            account.setText(cashMachine.accountIdToString());
74
+            name.setText(cashMachine.nameToString());
75
+            email.setText(cashMachine.emailToString());
76
+            balance.setText(cashMachine.balanceToString());
77
+        });
78
+
79
+
80
+        btnWithdraw.setOnAction(e -> {
81
+            double amount = Integer.parseInt(field2.getText());
82
+            cashMachine.withdraw(amount);
83
+
84
+            account.setText(cashMachine.accountIdToString());
85
+            name.setText(cashMachine.nameToString());
86
+            email.setText(cashMachine.emailToString());
87
+            balance.setText(cashMachine.balanceToString());
88
+        });
89
+
90
+        btnNewAccount.setOnAction(e -> {
91
+            primaryStage.setScene(scene3);
92
+            field2.clear();
93
+            field.clear();
94
+        });
95
+
96
+        btnExit.setOnAction(e -> {
97
+            cashMachine.exit();
98
+            field.clear();
99
+            primaryStage.setScene(scene1);
100
+        });
101
+
102
+        btnClose.setOnAction(e -> {
103
+            System.exit(0);
104
+        }); //add alert box to ask Are you sure??
105
+
106
+        btnSubmit2.setOnAction(e ->{
107
+            name1.clear(); email1.clear(); balance1.clear();
108
+            final ToggleGroup group = new ToggleGroup();
109
+            basicAcct.setToggleGroup(group);
110
+            premAcct.setToggleGroup(group);
111
+            if (basicAcct.isSelected()) {
112
+                cashMachine.newBasicAccount(name1.getText(), email1.getText(), Double.parseDouble(balance1.getText()));
113
+            } else {cashMachine.newPremiumAccount(name1.getText(), email1.getText(), Double.parseDouble(balance1.getText()));
114
+//            TextField newId = new TextField("Your account Id is " + cashMachine.accountIdToString());
115
+//            newId.setVisible(true);
116
+//            cashMachine.login(Integer.parseInt(cashMachine.accountIdToString()));
117
+            btnExit.fire();
118
+            }
119
+        });
120
+
121
+        //scene1 items
122
+        Label zipCloud = new Label("ZipCloud Bank");
123
+        Label phrase = new Label("We Make It Rain");
124
+        zipCloud.setPrefSize(180,60);
125
+        zipCloud.setFont(new Font("Gotham",24));
126
+        zipCloud.setAlignment(Pos.TOP_CENTER);
127
+        phrase.setPrefSize(150,20);
128
+        phrase.setPadding(new Insets(0,0,20,0));
129
+        phrase.setAlignment(Pos.TOP_CENTER);
130
+
131
+        fp.getChildren().addAll(btnSubmit,btnClose);
132
+        fp.setPadding(new Insets(0,25,0,25));
133
+        vb.getChildren().addAll(zipCloud, phrase, field,fp);
134
+        vb.setAlignment(Pos.CENTER);
135
+        vb.setStyle("-fx-background-color: burlywood; -fx-padding: 2; -fx-border-color: dimgrey; -fx-border-style: solid; -fx-border-width: 2; -fx-vgap: 5");
136
+
137
+        //scene2items
138
+        Label zipCloud2 = new Label("ZipCloud Bank");
139
+        zipCloud2.setPrefSize(180,80);
140
+        zipCloud2.setFont(new Font("Gotham",24));
141
+        zipCloud2.setAlignment(Pos.TOP_CENTER);
142
+
143
+        Menu accountMenu = new Menu("Switch Accounts");
144
+        MenuBar menuBar = new MenuBar();
145
+        menuBar.getMenus().add(accountMenu);
146
+        ArrayList<String> accountList = cashMachine.listAccounts();
147
+        for(String acct : accountList) {
148
+                MenuItem newItem = new MenuItem(acct);
149
+                newItem.setOnAction(e -> btnExit.fire());
150
+                accountMenu.getItems().add(newItem);
151
+        }
152
+        fp2.getChildren().addAll(btnDeposit,btnWithdraw,btnNewAccount,btnExit, btnClose);
153
+        fp2.setAlignment(Pos.CENTER);
154
+
155
+        gp2.setVgap(.1);
156
+        gp2.setHgap(10);
157
+        gp2.setPadding(new Insets(25,25,25,25));
158
+        gp2.setOpacity(20);
159
+        gp2.setAlignment(Pos.BOTTOM_CENTER);
160
+        gp2.setPrefSize(100,50);
161
+        gp2.setStyle("-fx-font-size: 12; -fx-font-smoothing-type: LCD; -fx-font-family: fantasy");
162
+
163
+        gp2.add(account,0,0);
164
+        gp2.add(name,0,1);
165
+        gp2.add(email,1,0);
166
+        gp2.add(balance,1,1);
167
+        vb2.getChildren().addAll(menuBar, zipCloud2, field2,fp2,gp2);
168
+        vb2.setAlignment(Pos.BOTTOM_CENTER);
169
+        vb2.setStyle("-fx-background-color: burlywood; -fx-padding: 2; -fx-border-color: dimgrey; -fx-border-style: solid; -fx-border-width: 2; -fx-vgap: 5");
170
+
171
+        //scene3items
172
+        vb3.getChildren().addAll(name1,email1,balance1,basicAcct,premAcct,btnSubmit2);
173
+        vb3.setStyle("-fx-background-color: burlywood; -fx-padding: 2; -fx-border-color: dimgrey; -fx-border-style: solid; -fx-border-width: 2; -fx-vgap: 5");
174
+
175
+        primaryStage.setTitle("Zip Cloud Bank");
176
+        primaryStage.setScene(scene1);
177
+        primaryStage.show();
178
+    }
179
+}

+ 15
- 0
src/main/java/rocks/zipcode/atm/bank/Bank.java Visa fil

@@ -32,6 +32,21 @@ public class Bank {
32 32
         )));
33 33
     }
34 34
 
35
+    public void addBasicAccount(String name, String email, double balance) {
36
+         accounts.put(newId(), new BasicAccount(new AccountData(newId(), name, email, balance)));
37
+    }
38
+    public void addPremiumAccount(String name, String email, double balance) {
39
+        accounts.put(newId(), new PremiumAccount(new AccountData(newId(), name, email, balance)));
40
+    }
41
+
42
+    public int newId(){
43
+        int highestId = 0;
44
+        for(Integer id : accounts.keySet()){
45
+            if(id>highestId) highestId = id;
46
+        }
47
+        return highestId;
48
+    }
49
+
35 50
     public ActionResult<AccountData> getAccountById(int id) {
36 51
         Account account = accounts.get(id);
37 52