Browse Source

Passwords added

Lauren Green 6 years ago
parent
commit
7f6aeeb1d7

+ 24
- 30
README.TXT View File

@@ -4,8 +4,8 @@
4 4
 
5 5
 A simple cash account <-> bank system implementation (very loosely modelled!)
6 6
 
7
-This project uses JavaFX for the user interface toolkit. JavaFX is a software platform for creating 
8
-and delivering desktop applications, as well as rich Internet applications (RIAs) 
7
+This project uses JavaFX for the user interface toolkit. JavaFX is a software platform for creating
8
+and delivering desktop applications, as well as rich Internet applications (RIAs)
9 9
 that can run across a wide variety of devices. It is part of the standard Java distribution.
10 10
 
11 11
 Welcome to your first App. "ZipCloudBank", a local Wilmington fintech startup, has a minimally
@@ -16,24 +16,24 @@ The Board of Directors of ZipCloudBank have empowered me to let you take a crack
16 16
 and improving their app over this weekend. Impressed that you are a ZipCode student, they are
17 17
 expecting great things. Don't panic: we think you can do this.
18 18
 
19
-The point of this lab is to read thru some existing code, in this case, a program/app that 
19
+The point of this lab is to read thru some existing code, in this case, a program/app that
20 20
 launches a window on your computer and lets you play with a couple of "banking accounts".
21 21
 You should run the app, learn how to use it, so you understand what it does. It is not,
22 22
 shall we say, user-friendly. So you may find what you have to do to make it work somewhat
23
-awkward. 
23
+awkward.
24 24
 
25
-Then, you should read thru the code repository seeing how the code actually implements the things you 
25
+Then, you should read thru the code repository seeing how the code actually implements the things you
26 26
 see when you run the code. Find the "main" routine, which is where the app starts up. Trace from there
27 27
 to see what code gets called where and when. Trace how the operations of the code work.
28 28
 
29 29
 Finally, you are to add some new functionality to the app, to make it "more useful, powerful &
30
-more rewarding for the user". 
30
+more rewarding for the user".
31 31
 Your effort will be met with promotions, parades, and stock options. (no, just kidding).
32 32
 
33 33
 Lab Brief
34 34
 =========
35 35
 
36
-Notice the structure of the current project before you start. Read thru the 
36
+Notice the structure of the current project before you start. Read thru the
37 37
 code up here on git.zipcode.rocks.
38 38
 Read thru the code. READ THRU THE CODE.
39 39
 READ THRU THE CODE.
@@ -63,23 +63,23 @@ Notice when reading the code...
63 63
 Things to Change for the Lab
64 64
 ============================
65 65
 
66
-FIRST, fork this repo into your own account. 
66
+FIRST, fork this repo into your own account.
67 67
        =====================================
68 68
 
69
-     After getting each of these items completed, 
70
-     be sure to do a 'git commit' to save you work. 
69
+     After getting each of these items completed,
70
+     be sure to do a 'git commit' to save you work.
71 71
      Learn your git.
72
-     Never Lose Code. 
72
+     Never Lose Code.
73 73
      NEVER LOSE CODE. EVER. :-)
74 74
 
75 75
 How about making a new git branch, named "dev" from the master branch for you to do all
76 76
 your work in?? (what great idea!)
77 77
 
78
-NOW, maybe you're ready to start making changes. 
78
+NOW, maybe you're ready to start making changes.
79 79
 
80 80
 
81 81
 
82
-* Add more accounts to the default constructor of the Bank class.
82
+X  * Add more accounts to the default constructor of the Bank class.
83 83
 * When you overdraft an account, print an alert message to the areaInfo object on the window.
84 84
 
85 85
 Additional things to add
@@ -89,24 +89,18 @@ You need not do these things in this order. Do as many as you can. When you fini
89 89
 make sure the project runs. (Else the Board... well, disappointment lies that direction.)
90 90
      ---------------------
91 91
 
92
-* Make the account display more user friendly
93
-  * add a Form layout that has separate TextFields for each piece of account info. 
94
-  * You'll probably find a layout that lets you do this, a little like the FlowPane.
95
-  * Make the login stuff more clear
96
-  * Disable the three buttons that operate on an account until a login happens 
97
-  * and then enable them. add another TextField for the amount entries. 
98
-  * Make it different from the TextField where you set the account ID.
92
+Make the account display more user friendly
93
+X   * Add a Form layout that has separate TextFields for each piece of account info. You'll probably find a layout that lets you do this, a little like the FlowPane.
94
+X  * Make the login stuff more clear
95
+X  * Disable the three buttons that operate on an account until a login happens and then enable them.
96
+X  * Add another TextField for the amount entries. Make it different from the TextField where you set the account ID.
97
+X  * Enable the amount entries to be floating point numbers instead of just integers when doing deposits and withdrawals.
98
+X   * Add a menu with a list of accounts in it and the menu action switched to that account. You may find that JavaFX already has such a thing.
99 99
 
100
-* Enable the amount entries to be floating point numbers instead of 
101
-  just integers when doing deposits and withdrawals.
102
-
103
-* Add a menu with a list of accounts in it and the menu action switched 
104
-  to that account. You may find that JavaFX already has such a thing.
105
-
106
-**** Add a New Account Window(!) that takes in the info required thru 
107
-     TextFields and creates the correct objects so that is can be changed 
100
+**** Add a New Account Window(!) that takes in the info required thru
101
+     TextFields and creates the correct objects so that is can be changed
108 102
      like the pre-wired accounts.
109 103
 
110
-NB: When googling for information on how to do all this, 
111
-be sure you start every query with "javafx " and your other search terms. 
104
+NB: When googling for information on how to do all this,
105
+be sure you start every query with "javafx " and your other search terms.
112 106
 That will limit the results to things that probably are closer to what you need.

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

@@ -29,6 +29,10 @@ public class CashMachine {
29 29
         accountData = data;
30 30
     };
31 31
 
32
+    public void resetPassword(int accountNumber, String newPassword) {
33
+        bank.resetPassword(accountNumber, newPassword);
34
+    }
35
+
32 36
     public ObservableList<Integer> getIdList() {
33 37
 
34 38
         ObservableList<Integer> idList = FXCollections.observableArrayList(bank.getIdList());
@@ -36,6 +40,16 @@ public class CashMachine {
36 40
         return idList;
37 41
     }
38 42
 
43
+    public String message(String message) {
44
+        return message;
45
+    }
46
+
47
+    public boolean checkPassword(int accountNumber, String password) {
48
+
49
+        password.toLowerCase();
50
+        return bank.getPassword(accountNumber).equals(password);
51
+    }
52
+
39 53
     public void login(int id) {
40 54
         tryCall(
41 55
                 () -> bank.getAccountById(id),
@@ -61,6 +75,10 @@ public class CashMachine {
61 75
         }
62 76
     }
63 77
 
78
+    public ActionResult<AccountData> checkWithdraw(AccountData accountData, float amount) {
79
+        return bank.withdraw(accountData, amount);
80
+    }
81
+
64 82
     public void exit() {
65 83
         if (accountData != null) {
66 84
             accountData = null;

+ 26
- 7
src/main/java/rocks/zipcode/atm/CashMachineApp.java View File

@@ -67,10 +67,18 @@ public class CashMachineApp extends Application {
67 67
         btnWithdraw.setOnAction(e -> {
68 68
             float amount = Float.parseFloat(field2.getText());
69 69
             cashMachine.withdraw(amount);
70
-
71 70
             areaInfo.setText(cashMachine.toString());
72 71
         });
73 72
 
73
+        Button btnResetPassword = new Button("Reset Password");
74
+        btnResetPassword.setDisable(true);
75
+        btnResetPassword.setOnAction(e -> {
76
+            int id = Integer.parseInt(accountNumbers.getValue().toString());
77
+            String password = field.getText();
78
+            cashMachine.resetPassword(id, password);
79
+            areaInfo.setText(cashMachine.message("Password Reset."));
80
+        });
81
+
74 82
         Button btnExit = new Button("Log Out");
75 83
         btnExit.setOnAction(e -> {
76 84
             cashMachine.exit();
@@ -79,18 +87,27 @@ public class CashMachineApp extends Application {
79 87
             areaInfo.clear();
80 88
             btnDeposit.setDisable(true);
81 89
             btnWithdraw.setDisable(true);
90
+            btnResetPassword.setDisable(true);
82 91
         });
83 92
 
84 93
         Button btnSubmit = new Button("Enter");
85 94
         btnSubmit.setOnAction(e -> {
86 95
             int id = Integer.parseInt(accountNumbers.getValue().toString());
87
-            cashMachine.login(id);
88
-
89
-            areaInfo.setText(cashMachine.toString());
90
-            btnDeposit.setDisable(false);
91
-            btnWithdraw.setDisable(false);
96
+            String password = field.getText();
97
+            if(cashMachine.checkPassword(id, password)) {
98
+                cashMachine.login(id);
99
+                areaInfo.setText(cashMachine.toString());
100
+                btnDeposit.setDisable(false);
101
+                btnWithdraw.setDisable(false);
102
+                btnResetPassword.setDisable(false);
103
+                password = "New Password:";
104
+            } else {
105
+                areaInfo.setText(cashMachine.message("Incorrect Password.  Try Again."));
106
+            }
92 107
         });
93 108
 
109
+
110
+
94 111
         /*
95 112
         String path = "https://drive.google.com/file/d/1PR_cLhzJ9IFcnWF46QSX_WEcnFT-uI0Q/view?usp=sharing";
96 113
 
@@ -100,6 +117,7 @@ public class CashMachineApp extends Application {
100 117
         FlowPane flowpane = new FlowPane();
101 118
 
102 119
         flowpane.getChildren().add(btnSubmit);
120
+        flowpane.getChildren().add(btnResetPassword);
103 121
         flowpane.getChildren().add(btnNewAccount);
104 122
 
105 123
         FlowPane flowpane2 = new FlowPane();
@@ -113,7 +131,8 @@ public class CashMachineApp extends Application {
113 131
         field.setStyle("-fx-background-color: lightgrey;");
114 132
         field2.setStyle("-fx-background-color: lightgrey;");
115 133
         Label fieldLabel = new Label("Account Number:");
116
-        vbox.getChildren().addAll(fieldLabel, accountNumbers, flowpane, fieldLabel2, field2, flowpane2, accountInfo2, areaInfo);
134
+        Label password = new Label("Password:");
135
+        vbox.getChildren().addAll(fieldLabel, accountNumbers, password, field, flowpane, fieldLabel2, field2, flowpane2, accountInfo2, areaInfo);
117 136
 
118 137
 
119 138
 

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

@@ -14,6 +14,7 @@ import java.util.Map;
14 14
 public class Bank {
15 15
 
16 16
     private Map<Integer, Account> accounts = new HashMap<>();
17
+    private Map<Integer, String> passwords = new HashMap<>();
17 18
     //private static int nextId = 1000;
18 19
 
19 20
     /* Add options for user to create an account and have a number issued to them. */
@@ -23,50 +24,73 @@ public class Bank {
23 24
                 1000, "Nick Foles", "LIImvp@gmail.com", 500
24 25
         )));
25 26
 
27
+        passwords.put(1000, "password");
28
+
26 29
         accounts.put(1100, new BasicAccount(new AccountData(
27 30
                 1100, "Dan Green", "dgreen@gmail.com", 100000
28 31
         )));
29 32
 
33
+        passwords.put(1100, "password");
34
+
30 35
         accounts.put(1200, new BasicAccount(new AccountData(
31 36
                 1200, "Billy Madison", "back2school@gmail.com", 500
32 37
         )));
33 38
 
39
+        passwords.put(1200, "password");
40
+
34 41
         accounts.put(1300, new BasicAccount(new AccountData(
35 42
                 1300, "Chase Utley", "grandpa@gmail.com", 2008
36 43
         )));
37 44
 
45
+        passwords.put(1300, "password");
46
+
38 47
         accounts.put(1400, new PremiumAccount(new AccountData(
39 48
                 1400, "Elle Woods", "pink@gmail.com", 20
40 49
         )));
41 50
 
51
+        passwords.put(1400, "password");
52
+
42 53
         accounts.put(1500, new PremiumAccount(new AccountData(
43 54
                 1500, "Harry Potter", "seeker4life@wizmail.com", 200
44 55
         )));
45 56
 
57
+        passwords.put(1500, "password");
58
+
46 59
         accounts.put(1600, new BasicAccount(new AccountData(
47 60
                 1600, "Hermione Granger", "librarylover@gmail.com", 950
48 61
         )));
49 62
 
63
+        passwords.put(1600, "password");
64
+
50 65
         accounts.put(1700, new BasicAccount(new AccountData(
51 66
                 1700, "Hayden Stewart", "hstew@gmail.com", 100
52 67
         )));
53 68
 
69
+        passwords.put(1700, "password");
70
+
54 71
         accounts.put(1800, new BasicAccount(new AccountData(
55 72
                 1800, "Jack Traven", "speed@gmail.com", 50
56 73
         )));
57 74
 
75
+        passwords.put(1800, "password");
76
+
58 77
         accounts.put(1900, new BasicAccount(new AccountData(
59 78
                 1900, "Jimmy Fallon", "jimmy@nbc.com", 1000
60 79
         )));
61 80
 
81
+        passwords.put(1900, "password");
82
+
62 83
         accounts.put(2000, new PremiumAccount(new AccountData(
63 84
                 2000, "Frankie Smit", "frank@gmail.com", 2040
64 85
         )));
65 86
 
87
+        passwords.put(2000, "password");
88
+
66 89
         accounts.put(2100, new PremiumAccount(new AccountData(
67 90
                 2100, "Ron Weasley", "ron@wizmail.com", 2003
68 91
         )));
69 92
 
93
+        passwords.put(2100, "password");
70 94
     }
71 95
 
72 96
 /*How to use this???
@@ -85,6 +109,14 @@ public class Bank {
85 109
 
86 110
 */
87 111
 
112
+    public String getPassword(int accountNumber) {
113
+        return passwords.get(accountNumber);
114
+    }
115
+
116
+    public void resetPassword(int accountNumber, String newPassword) {
117
+        passwords.put(accountNumber, newPassword);
118
+    }
119
+
88 120
     public ObservableList<Integer> getIdList() {
89 121
 
90 122
         ObservableList<Integer> idList = FXCollections.observableArrayList();
@@ -123,4 +155,6 @@ public class Bank {
123 155
             return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
124 156
         }
125 157
     }
158
+
159
+
126 160
 }