#8 CashMachine

otevřený
thulasipuppala chce sloučit 1 revizí z větve thulasipuppala/CashMachine:master do větve master

binární
.DS_Store Zobrazit soubor


+ 1
- 1
README.md Zobrazit soubor

@@ -10,7 +10,7 @@ viable product in CashMachine. The response from customers has been, shall we sa
10 10
 The original coder has gone off to another startup, in Thailand, where they code on surfboards
11 11
 all day long.
12 12
 The Board of Directors of ZipCloudBank have empowered me to let you take a crack at "upping their game"
13
-and improving their app over this weekend. Impressed that you are a ZipCode student, they are
13
+and improving their app over this **weekend. Impressed that you are a ZipCode student, they are
14 14
 expecting great things. Don't panic: we think you can do this.
15 15
 
16 16
 The point of this lab is to read thru some existing code, in this case, a program/app that 

binární
src/.DS_Store Zobrazit soubor


binární
src/main/.DS_Store Zobrazit soubor


binární
src/main/java/.DS_Store Zobrazit soubor


binární
src/main/java/rocks/.DS_Store Zobrazit soubor


binární
src/main/java/rocks/zipcode/.DS_Store Zobrazit soubor


binární
src/main/java/rocks/zipcode/atm/.DS_Store Zobrazit soubor


+ 69
- 2
src/main/java/rocks/zipcode/atm/CashMachine.java Zobrazit soubor

@@ -3,17 +3,37 @@ package rocks.zipcode.atm;
3 3
 import rocks.zipcode.atm.bank.AccountData;
4 4
 import rocks.zipcode.atm.bank.Bank;
5 5
 
6
+import java.awt.event.ActionEvent;
6 7
 import java.util.function.Consumer;
7 8
 import java.util.function.Supplier;
8 9
 
10
+import javafx.fxml.FXML;
11
+import javafx.scene.control.Label;
12
+import javafx.scene.control.PasswordField;
13
+import javafx.scene.control.TextField;
14
+
9 15
 /**
10 16
  * @author ZipCodeWilmington
11 17
  */
12 18
 public class CashMachine {
13 19
 
20
+    @FXML
21
+    private Label title;
22
+
23
+    @FXML
24
+    private TextField username;
25
+
26
+    @FXML
27
+    private PasswordField password;
28
+
29
+    @FXML
30
+    private Label loginFailed;
31
+
14 32
     private final Bank bank;
15 33
     private AccountData accountData = null;
16
-
34
+    /*private String message = null;
35
+    private Integer amount = 0;
36
+*/
17 37
     public CashMachine(Bank bank) {
18 38
         this.bank = bank;
19 39
     }
@@ -22,6 +42,23 @@ public class CashMachine {
22 42
         accountData = data;
23 43
     };
24 44
 
45
+    /*private Consumer<String> update2 = data -> {
46
+        message = data;
47
+    };
48
+    private Consumer<Integer> update3 = data -> {
49
+        amount = data;
50
+    };*/
51
+
52
+    public void login(ActionEvent event){
53
+
54
+        if(username.getText().equals("user") && password.getText().equals("password")){
55
+            title.setText("Login Success");
56
+        }
57
+        else
58
+            loginFailed.setVisible(true);
59
+
60
+    }
61
+
25 62
     public void login(int id) {
26 63
         tryCall(
27 64
                 () -> bank.getAccountById(id),
@@ -29,6 +66,23 @@ public class CashMachine {
29 66
         );
30 67
     }
31 68
 
69
+   /* public void checkAccount(){
70
+        if(accountData != null){
71
+            tryCall(
72
+                    () -> bank.getAccountType(accountData), update
73
+            );
74
+        }
75
+    }*/
76
+
77
+    public void checkBalance() {
78
+        if(accountData != null){
79
+            tryCall(
80
+                    () -> bank.getBalance(accountData), update
81
+            );
82
+        }
83
+
84
+    }
85
+
32 86
     public void deposit(int amount) {
33 87
         if (accountData != null) {
34 88
             tryCall(
@@ -53,9 +107,13 @@ public class CashMachine {
53 107
         }
54 108
     }
55 109
 
110
+    public String getUser(){
111
+        return "Welcome " + accountData.getName();
112
+    }
113
+
56 114
     @Override
57 115
     public String toString() {
58
-        return accountData != null ? accountData.toString() : "Try account 1000 or 2000 and click submit.";
116
+        return accountData != null ? accountData.toString() : "Try giving a valid account number and click submit.";
59 117
     }
60 118
 
61 119
     private <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {
@@ -72,4 +130,13 @@ public class CashMachine {
72 130
             System.out.println("Error: " + e.getMessage());
73 131
         }
74 132
     }
133
+
134
+
135
+    public String goodBye() {
136
+        return "Good Bye!! Thanks for using our Cash Machine";
137
+    }
138
+
139
+    public String getBalance() {
140
+        return "The Balance in your account is "+ this.accountData.getBalance();
141
+    }
75 142
 }

+ 61
- 4
src/main/java/rocks/zipcode/atm/CashMachineApp.java Zobrazit soubor

@@ -1,5 +1,9 @@
1 1
 package rocks.zipcode.atm;
2 2
 
3
+import javafx.fxml.FXMLLoader;
4
+import javafx.scene.Group;
5
+import javafx.scene.image.ImageView;
6
+
3 7
 import rocks.zipcode.atm.bank.Bank;
4 8
 import javafx.application.Application;
5 9
 import javafx.scene.Parent;
@@ -11,25 +15,54 @@ import javafx.scene.layout.VBox;
11 15
 import javafx.stage.Stage;
12 16
 import javafx.scene.layout.FlowPane;
13 17
 
18
+
19
+
14 20
 /**
15 21
  * @author ZipCodeWilmington
16 22
  */
17 23
 public class CashMachineApp extends Application {
18 24
 
25
+
26
+
19 27
     private TextField field = new TextField();
20 28
     private CashMachine cashMachine = new CashMachine(new Bank());
21 29
 
22 30
     private Parent createContent() {
23 31
         VBox vbox = new VBox(10);
24
-        vbox.setPrefSize(600, 600);
32
+        vbox.setPrefSize(800, 800);
25 33
 
26 34
         TextArea areaInfo = new TextArea();
35
+        areaInfo.setStyle("-fx-background-color: aquamarine;");
36
+
37
+       /* Button btnCreateBasicAccount = new Button("Create Account");
38
+        btnCreateBasicAccount.setOnAction(e -> {
39
+            int id = Integer.parseInt(field.getText());
40
+            cashMachine.login(id);
41
+
42
+            areaInfo.setText(cashMachine.toString());
43
+        });*/
27 44
 
28 45
         Button btnSubmit = new Button("Set Account ID");
29 46
         btnSubmit.setOnAction(e -> {
30 47
             int id = Integer.parseInt(field.getText());
31 48
             cashMachine.login(id);
32 49
 
50
+            areaInfo.setText(cashMachine.getUser());
51
+        });
52
+
53
+        Button btnCheckBalance = new Button("Check Balance");
54
+        btnCheckBalance.setOnAction(e -> {
55
+            int amount = Integer.parseInt(field.getText());
56
+            cashMachine.checkBalance();
57
+
58
+            areaInfo.setText(cashMachine.getBalance());
59
+        });
60
+
61
+        Button btnAccountDetails = new Button("Account Information");
62
+        btnAccountDetails.setOnAction(e -> {
63
+            int amount = Integer.parseInt(field.getText());
64
+            cashMachine.toString();
65
+
33 66
             areaInfo.setText(cashMachine.toString());
34 67
         });
35 68
 
@@ -38,7 +71,7 @@ public class CashMachineApp extends Application {
38 71
             int amount = Integer.parseInt(field.getText());
39 72
             cashMachine.deposit(amount);
40 73
 
41
-            areaInfo.setText(cashMachine.toString());
74
+            areaInfo.setText(cashMachine.getBalance());
42 75
         });
43 76
 
44 77
         Button btnWithdraw = new Button("Withdraw");
@@ -46,30 +79,54 @@ public class CashMachineApp extends Application {
46 79
             int amount = Integer.parseInt(field.getText());
47 80
             cashMachine.withdraw(amount);
48 81
 
49
-            areaInfo.setText(cashMachine.toString());
82
+            areaInfo.setText(cashMachine.getBalance());
50 83
         });
51 84
 
52 85
         Button btnExit = new Button("Exit");
53 86
         btnExit.setOnAction(e -> {
54 87
             cashMachine.exit();
55 88
 
56
-            areaInfo.setText(cashMachine.toString());
89
+            areaInfo.setText(cashMachine.goodBye());
57 90
         });
58 91
 
59 92
         FlowPane flowpane = new FlowPane();
60 93
 
61 94
         flowpane.getChildren().add(btnSubmit);
95
+        flowpane.getChildren().add(btnCheckBalance);
62 96
         flowpane.getChildren().add(btnDeposit);
63 97
         flowpane.getChildren().add(btnWithdraw);
98
+        flowpane.getChildren().add(btnAccountDetails);
64 99
         flowpane.getChildren().add(btnExit);
100
+
101
+
102
+        //Image image = new Image("file:atm.jpg");
103
+        ImageView mv = new ImageView("file:atm.jpg");
104
+
105
+        Group root = new Group();
106
+        root.getChildren().addAll(mv);
107
+
108
+        vbox.setStyle("-fx-background-color: silver; -fx-padding: 20; -fx-font-size: 20;");
65 109
         vbox.getChildren().addAll(field, flowpane, areaInfo);
66 110
         return vbox;
67 111
     }
68 112
 
69 113
     @Override
70 114
     public void start(Stage stage) throws Exception {
115
+
116
+        stage.setTitle("ZIPCLOUD BANK");
71 117
         stage.setScene(new Scene(createContent()));
72 118
         stage.show();
119
+
120
+        /*try {
121
+
122
+            Parent root = FXMLLoader.load(getClass().getResource("/Users/thulasipuppala/Labs/CashMachine/src/main/java/rocks/zipcode/atm/Login.fxml"));
123
+            Scene scene1 = new Scene(root, 600, 600);
124
+            stage.setScene(scene1);
125
+            stage.show();
126
+        }
127
+        catch (Exception e){
128
+            e.printStackTrace();
129
+        }*/
73 130
     }
74 131
 
75 132
     public static void main(String[] args) {

+ 31
- 0
src/main/java/rocks/zipcode/atm/Login.fxml Zobrazit soubor

@@ -0,0 +1,31 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+
3
+<?import javafx.scene.control.Button?>
4
+<?import javafx.scene.control.Label?>
5
+<?import javafx.scene.control.PasswordField?>
6
+<?import javafx.scene.control.TextField?>
7
+<?import javafx.scene.layout.AnchorPane?>
8
+<?import javafx.scene.text.Font?>
9
+
10
+
11
+<AnchorPane fx:id="loginFailed" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="rocks.zipcode.atm.CashMachine">
12
+   <children>
13
+      <TextField fx:id="username" layoutX="174.0" layoutY="139.0" prefHeight="55.0" prefWidth="243.0" promptText="UserName">
14
+         <font>
15
+            <Font size="18.0" />
16
+         </font>
17
+      </TextField>
18
+      <Button layoutX="263.0" layoutY="300.0" mnemonicParsing="false" onAction="#login" prefHeight="37.0" prefWidth="74.0" text="Login" />
19
+      <PasswordField fx:id="password" layoutX="174.0" layoutY="219.0" prefHeight="55.0" prefWidth="243.0" promptText="Password">
20
+         <font>
21
+            <Font size="18.0" />
22
+         </font>
23
+      </PasswordField>
24
+      <Label alignment="CENTER" layoutX="231.0" layoutY="352.0" prefHeight="17.0" prefWidth="133.0" text="Login Failed!" textFill="#d32626" visible="false" />
25
+      <Label alignment="CENTER" contentDisplay="CENTER" layoutX="76.0" layoutY="25.0" prefHeight="92.0" prefWidth="434.0" text="ZIPCLOUD BANK" textFill="#3f599a">
26
+         <font>
27
+            <Font name="Apple Color Emoji" size="48.0" />
28
+         </font>
29
+      </Label>
30
+   </children>
31
+</AnchorPane>

+ 32
- 0
src/main/java/rocks/zipcode/atm/LoginWindow.java Zobrazit soubor

@@ -0,0 +1,32 @@
1
+package rocks.zipcode.atm;
2
+
3
+import javafx.application.Application;
4
+import javafx.fxml.FXML;
5
+import javafx.fxml.FXMLLoader;
6
+import javafx.scene.Scene;
7
+import javafx.stage.Stage;
8
+
9
+import rocks.zipcode.atm.bank.Bank;
10
+import javafx.application.Application;
11
+import javafx.scene.Parent;
12
+import javafx.scene.control.Button;
13
+import javafx.scene.control.TextArea;
14
+import javafx.scene.control.TextField;
15
+import javafx.scene.layout.VBox;
16
+import javafx.scene.layout.FlowPane;
17
+
18
+public class LoginWindow extends Application {
19
+
20
+    private CashMachine cashMachine = new CashMachine(new Bank());
21
+
22
+    public static void main(String[] args) {
23
+        launch(args);
24
+    }
25
+
26
+    @Override
27
+    public void start(Stage primaryStage) {
28
+
29
+
30
+
31
+    }
32
+}

+ 22
- 4
src/main/java/rocks/zipcode/atm/bank/Bank.java Zobrazit soubor

@@ -14,11 +14,19 @@ public class Bank {
14 14
 
15 15
     public Bank() {
16 16
         accounts.put(1000, new BasicAccount(new AccountData(
17
-                1000, "Example 1", "example1@gmail.com", 500
17
+                1000, "Sreya", "sreya@gmail.com", 500
18 18
         )));
19 19
 
20
-        accounts.put(2000, new PremiumAccount(new AccountData(
21
-                2000, "Example 2", "example2@gmail.com", 200
20
+        accounts.put(2000, new BasicAccount(new AccountData(
21
+                2000, "Sreeram", "sreeram@gmail.com", 200
22
+        )));
23
+
24
+        accounts.put(3000, new PremiumAccount(new AccountData(
25
+                3000, "Thulasi", "thulasi@gmail.com", 20000
26
+        )));
27
+
28
+        accounts.put(4000, new PremiumAccount(new AccountData(
29
+                4000, "Chandra", "chandra@gmail.com", 20000
22 30
         )));
23 31
     }
24 32
 
@@ -28,10 +36,17 @@ public class Bank {
28 36
         if (account != null) {
29 37
             return ActionResult.success(account.getAccountData());
30 38
         } else {
31
-            return ActionResult.fail("No account with id: " + id + "\nTry account 1000 or 2000");
39
+            return ActionResult.fail("No account with id: " + id + "\nTry again");
32 40
         }
33 41
     }
34 42
 
43
+    public ActionResult<AccountData> getBalance(AccountData accountData) {
44
+        Account account = accounts.get(accountData.getId());
45
+        account.getBalance();
46
+
47
+        return ActionResult.success(account.getAccountData());
48
+    }
49
+
35 50
     public ActionResult<AccountData> deposit(AccountData accountData, int amount) {
36 51
         Account account = accounts.get(accountData.getId());
37 52
         account.deposit(amount);
@@ -49,4 +64,7 @@ public class Bank {
49 64
             return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
50 65
         }
51 66
     }
67
+
68
+
69
+
52 70
 }