#8 CashMachine

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

BIN
.DS_Store View File


+ 1
- 1
README.md View File

10
 The original coder has gone off to another startup, in Thailand, where they code on surfboards
10
 The original coder has gone off to another startup, in Thailand, where they code on surfboards
11
 all day long.
11
 all day long.
12
 The Board of Directors of ZipCloudBank have empowered me to let you take a crack at "upping their game"
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
 expecting great things. Don't panic: we think you can do this.
14
 expecting great things. Don't panic: we think you can do this.
15
 
15
 
16
 The point of this lab is to read thru some existing code, in this case, a program/app that 
16
 The point of this lab is to read thru some existing code, in this case, a program/app that 

BIN
src/.DS_Store View File


BIN
src/main/.DS_Store View File


BIN
src/main/java/.DS_Store View File


BIN
src/main/java/rocks/.DS_Store View File


BIN
src/main/java/rocks/zipcode/.DS_Store View File


BIN
src/main/java/rocks/zipcode/atm/.DS_Store View File


+ 69
- 2
src/main/java/rocks/zipcode/atm/CashMachine.java View File

3
 import rocks.zipcode.atm.bank.AccountData;
3
 import rocks.zipcode.atm.bank.AccountData;
4
 import rocks.zipcode.atm.bank.Bank;
4
 import rocks.zipcode.atm.bank.Bank;
5
 
5
 
6
+import java.awt.event.ActionEvent;
6
 import java.util.function.Consumer;
7
 import java.util.function.Consumer;
7
 import java.util.function.Supplier;
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
  * @author ZipCodeWilmington
16
  * @author ZipCodeWilmington
11
  */
17
  */
12
 public class CashMachine {
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
     private final Bank bank;
32
     private final Bank bank;
15
     private AccountData accountData = null;
33
     private AccountData accountData = null;
16
-
34
+    /*private String message = null;
35
+    private Integer amount = 0;
36
+*/
17
     public CashMachine(Bank bank) {
37
     public CashMachine(Bank bank) {
18
         this.bank = bank;
38
         this.bank = bank;
19
     }
39
     }
22
         accountData = data;
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
     public void login(int id) {
62
     public void login(int id) {
26
         tryCall(
63
         tryCall(
27
                 () -> bank.getAccountById(id),
64
                 () -> bank.getAccountById(id),
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
     public void deposit(int amount) {
86
     public void deposit(int amount) {
33
         if (accountData != null) {
87
         if (accountData != null) {
34
             tryCall(
88
             tryCall(
53
         }
107
         }
54
     }
108
     }
55
 
109
 
110
+    public String getUser(){
111
+        return "Welcome " + accountData.getName();
112
+    }
113
+
56
     @Override
114
     @Override
57
     public String toString() {
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
     private <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {
119
     private <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {
72
             System.out.println("Error: " + e.getMessage());
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 View File

1
 package rocks.zipcode.atm;
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
 import rocks.zipcode.atm.bank.Bank;
7
 import rocks.zipcode.atm.bank.Bank;
4
 import javafx.application.Application;
8
 import javafx.application.Application;
5
 import javafx.scene.Parent;
9
 import javafx.scene.Parent;
11
 import javafx.stage.Stage;
15
 import javafx.stage.Stage;
12
 import javafx.scene.layout.FlowPane;
16
 import javafx.scene.layout.FlowPane;
13
 
17
 
18
+
19
+
14
 /**
20
 /**
15
  * @author ZipCodeWilmington
21
  * @author ZipCodeWilmington
16
  */
22
  */
17
 public class CashMachineApp extends Application {
23
 public class CashMachineApp extends Application {
18
 
24
 
25
+
26
+
19
     private TextField field = new TextField();
27
     private TextField field = new TextField();
20
     private CashMachine cashMachine = new CashMachine(new Bank());
28
     private CashMachine cashMachine = new CashMachine(new Bank());
21
 
29
 
22
     private Parent createContent() {
30
     private Parent createContent() {
23
         VBox vbox = new VBox(10);
31
         VBox vbox = new VBox(10);
24
-        vbox.setPrefSize(600, 600);
32
+        vbox.setPrefSize(800, 800);
25
 
33
 
26
         TextArea areaInfo = new TextArea();
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
         Button btnSubmit = new Button("Set Account ID");
45
         Button btnSubmit = new Button("Set Account ID");
29
         btnSubmit.setOnAction(e -> {
46
         btnSubmit.setOnAction(e -> {
30
             int id = Integer.parseInt(field.getText());
47
             int id = Integer.parseInt(field.getText());
31
             cashMachine.login(id);
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
             areaInfo.setText(cashMachine.toString());
66
             areaInfo.setText(cashMachine.toString());
34
         });
67
         });
35
 
68
 
38
             int amount = Integer.parseInt(field.getText());
71
             int amount = Integer.parseInt(field.getText());
39
             cashMachine.deposit(amount);
72
             cashMachine.deposit(amount);
40
 
73
 
41
-            areaInfo.setText(cashMachine.toString());
74
+            areaInfo.setText(cashMachine.getBalance());
42
         });
75
         });
43
 
76
 
44
         Button btnWithdraw = new Button("Withdraw");
77
         Button btnWithdraw = new Button("Withdraw");
46
             int amount = Integer.parseInt(field.getText());
79
             int amount = Integer.parseInt(field.getText());
47
             cashMachine.withdraw(amount);
80
             cashMachine.withdraw(amount);
48
 
81
 
49
-            areaInfo.setText(cashMachine.toString());
82
+            areaInfo.setText(cashMachine.getBalance());
50
         });
83
         });
51
 
84
 
52
         Button btnExit = new Button("Exit");
85
         Button btnExit = new Button("Exit");
53
         btnExit.setOnAction(e -> {
86
         btnExit.setOnAction(e -> {
54
             cashMachine.exit();
87
             cashMachine.exit();
55
 
88
 
56
-            areaInfo.setText(cashMachine.toString());
89
+            areaInfo.setText(cashMachine.goodBye());
57
         });
90
         });
58
 
91
 
59
         FlowPane flowpane = new FlowPane();
92
         FlowPane flowpane = new FlowPane();
60
 
93
 
61
         flowpane.getChildren().add(btnSubmit);
94
         flowpane.getChildren().add(btnSubmit);
95
+        flowpane.getChildren().add(btnCheckBalance);
62
         flowpane.getChildren().add(btnDeposit);
96
         flowpane.getChildren().add(btnDeposit);
63
         flowpane.getChildren().add(btnWithdraw);
97
         flowpane.getChildren().add(btnWithdraw);
98
+        flowpane.getChildren().add(btnAccountDetails);
64
         flowpane.getChildren().add(btnExit);
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
         vbox.getChildren().addAll(field, flowpane, areaInfo);
109
         vbox.getChildren().addAll(field, flowpane, areaInfo);
66
         return vbox;
110
         return vbox;
67
     }
111
     }
68
 
112
 
69
     @Override
113
     @Override
70
     public void start(Stage stage) throws Exception {
114
     public void start(Stage stage) throws Exception {
115
+
116
+        stage.setTitle("ZIPCLOUD BANK");
71
         stage.setScene(new Scene(createContent()));
117
         stage.setScene(new Scene(createContent()));
72
         stage.show();
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
     public static void main(String[] args) {
132
     public static void main(String[] args) {

+ 31
- 0
src/main/java/rocks/zipcode/atm/Login.fxml View File

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 View File

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 View File

14
 
14
 
15
     public Bank() {
15
     public Bank() {
16
         accounts.put(1000, new BasicAccount(new AccountData(
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
         if (account != null) {
36
         if (account != null) {
29
             return ActionResult.success(account.getAccountData());
37
             return ActionResult.success(account.getAccountData());
30
         } else {
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
     public ActionResult<AccountData> deposit(AccountData accountData, int amount) {
50
     public ActionResult<AccountData> deposit(AccountData accountData, int amount) {
36
         Account account = accounts.get(accountData.getId());
51
         Account account = accounts.get(accountData.getId());
37
         account.deposit(amount);
52
         account.deposit(amount);
49
             return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
64
             return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
50
         }
65
         }
51
     }
66
     }
67
+
68
+
69
+
52
 }
70
 }