Demetrius Murray 6 years ago
parent
commit
d528bf6253

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


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

@@ -29,7 +29,7 @@ public class CashMachine {
29 29
         );
30 30
     }
31 31
 
32
-    public void deposit(int amount) {
32
+    public void deposit(double amount) {
33 33
         if (accountData != null) {
34 34
             tryCall(
35 35
                     () -> bank.deposit(accountData, amount),
@@ -38,7 +38,7 @@ public class CashMachine {
38 38
         }
39 39
     }
40 40
 
41
-    public void withdraw(int amount) {
41
+    public void withdraw(double amount) {
42 42
         if (accountData != null) {
43 43
             tryCall(
44 44
                     () -> bank.withdraw(accountData, amount),

+ 56
- 11
src/main/java/rocks/zipcode/atm/CashMachineApp.java View File

@@ -1,5 +1,6 @@
1 1
 package rocks.zipcode.atm;
2 2
 
3
+import javafx.scene.text.Text;
3 4
 import rocks.zipcode.atm.bank.Bank;
4 5
 import javafx.application.Application;
5 6
 import javafx.scene.Parent;
@@ -18,32 +19,78 @@ public class CashMachineApp extends Application {
18 19
 
19 20
     private TextField field = new TextField();
20 21
     private CashMachine cashMachine = new CashMachine(new Bank());
22
+    private TextField amountField = new TextField();
21 23
 
22 24
     private Parent createContent() {
25
+        field.setPromptText("Enter your account ID");
26
+        field.setFocusTraversable(false);
27
+
23 28
         VBox vbox = new VBox(10);
24 29
         vbox.setPrefSize(600, 600);
25 30
 
26
-        TextArea areaInfo = new TextArea();
31
+        Text areaInfo = new Text();
32
+        areaInfo.setVisible(false);
33
+
34
+        FlowPane flowpane = new FlowPane();
27 35
 
28
-        Button btnSubmit = new Button("Set Account ID");
36
+        Button btnSubmit = new Button("Login");
29 37
         btnSubmit.setOnAction(e -> {
30 38
             int id = Integer.parseInt(field.getText());
31 39
             cashMachine.login(id);
32
-
33
-            areaInfo.setText(cashMachine.toString());
34 40
         });
41
+//
42
+//        String[] acctFields;
43
+//        acctFields = String.valueOf(areaInfo).split("\n");
44
+
45
+//        Text acctID = new Text(acctFields[0]);
46
+//        Text name = new Text(acctFields[1]);
47
+//        Text email = new Text(acctFields[2]);
48
+//        Text balance = new Text(acctFields[3]);
49
+
50
+//        grid.setAlignment(Pos.CENTER_LEFT);
51
+//        grid.setHgap(10);
52
+//        grid.setVgap(10);
53
+//        Text gridTitle = new Text("Your account details");
54
+//        gridTitle.setFont(Font.font("Times New Roman", FontWeight.SEMI_BOLD, 14));
55
+//        grid.add(gridTitle, 0, 0, 2, 1);
56
+
57
+//        grid.add(acctID,1,1);
58
+//        grid.add(name,1,2);
59
+//        grid.add(email,1,3);
60
+//        grid.add(balance,1,4);
61
+
62
+//        grid.setPadding(new Insets(100,300,250,50));
63
+
64
+        flowpane.getChildren().add(btnSubmit);
65
+
66
+
67
+        vbox.getChildren().addAll(field, amountField, flowpane, areaInfo); //grid);
68
+        return vbox;
69
+    }
70
+
71
+    private Parent createContent2(){
72
+        FlowPane flowpane = new FlowPane();
73
+        Text areaInfo = new Text();
74
+        areaInfo.setVisible(true);
75
+        amountField.setPromptText("Enter amounts");
76
+        areaInfo.setText(cashMachine.toString());
77
+
78
+        VBox vbox = new VBox(10);
79
+        vbox.setPrefSize(600, 600);
35 80
 
36 81
         Button btnDeposit = new Button("Deposit");
37 82
         btnDeposit.setOnAction(e -> {
38
-            int amount = Integer.parseInt(field.getText());
83
+            double amount = Integer.parseInt(amountField.getText());
39 84
             cashMachine.deposit(amount);
40 85
 
41 86
             areaInfo.setText(cashMachine.toString());
87
+
42 88
         });
43 89
 
90
+
44 91
         Button btnWithdraw = new Button("Withdraw");
45 92
         btnWithdraw.setOnAction(e -> {
46
-            int amount = Integer.parseInt(field.getText());
93
+            double amount = Integer.parseInt(amountField.getText());
47 94
             cashMachine.withdraw(amount);
48 95
 
49 96
             areaInfo.setText(cashMachine.toString());
@@ -56,18 +103,16 @@ public class CashMachineApp extends Application {
56 103
             areaInfo.setText(cashMachine.toString());
57 104
         });
58 105
 
59
-        FlowPane flowpane = new FlowPane();
60
-
61
-        flowpane.getChildren().add(btnSubmit);
62 106
         flowpane.getChildren().add(btnDeposit);
63 107
         flowpane.getChildren().add(btnWithdraw);
64 108
         flowpane.getChildren().add(btnExit);
65
-        vbox.getChildren().addAll(field, flowpane, areaInfo);
109
+
110
+        vbox.getChildren().addAll(amountField, flowpane, areaInfo); //grid);
66 111
         return vbox;
67 112
     }
68
-
69 113
     @Override
70 114
     public void start(Stage stage) throws Exception {
115
+        stage.setTitle("Cash Machine");
71 116
         stage.setScene(new Scene(createContent()));
72 117
         stage.show();
73 118
     }

+ 5
- 5
src/main/java/rocks/zipcode/atm/bank/Account.java View File

@@ -15,11 +15,11 @@ public abstract class Account {
15 15
         return accountData;
16 16
     }
17 17
 
18
-    public void deposit(int amount) {
18
+    public void deposit(double amount) {
19 19
         updateBalance(getBalance() + amount);
20 20
     }
21 21
 
22
-    public boolean withdraw(int amount) {
22
+    public boolean withdraw(double amount) {
23 23
         if (canWithdraw(amount)) {
24 24
             updateBalance(getBalance() - amount);
25 25
             return true;
@@ -28,15 +28,15 @@ public abstract class Account {
28 28
         }
29 29
     }
30 30
 
31
-    protected boolean canWithdraw(int amount) {
31
+    protected boolean canWithdraw(double amount) {
32 32
         return getBalance() >= amount;
33 33
     }
34 34
 
35
-    public int getBalance() {
35
+    public double getBalance() {
36 36
         return accountData.getBalance();
37 37
     }
38 38
 
39
-    private void updateBalance(int newBalance) {
39
+    private void updateBalance(double newBalance) {
40 40
         accountData = new AccountData(accountData.getId(), accountData.getName(), accountData.getEmail(),
41 41
                 newBalance);
42 42
     }

+ 3
- 3
src/main/java/rocks/zipcode/atm/bank/AccountData.java View File

@@ -9,9 +9,9 @@ public final class AccountData {
9 9
     private final String name;
10 10
     private final String email;
11 11
 
12
-    private final int balance;
12
+    private final double balance;
13 13
 
14
-    AccountData(int id, String name, String email, int balance) {
14
+    AccountData(int id, String name, String email, double balance) {
15 15
         this.id = id;
16 16
         this.name = name;
17 17
         this.email = email;
@@ -30,7 +30,7 @@ public final class AccountData {
30 30
         return email;
31 31
     }
32 32
 
33
-    public int getBalance() {
33
+    public double getBalance() {
34 34
         return balance;
35 35
     }
36 36
 

+ 10
- 2
src/main/java/rocks/zipcode/atm/bank/Bank.java View File

@@ -20,6 +20,14 @@ public class Bank {
20 20
         accounts.put(2000, new PremiumAccount(new AccountData(
21 21
                 2000, "Example 2", "example2@gmail.com", 200
22 22
         )));
23
+
24
+        accounts.put(3000, new BasicAccount(new AccountData(
25
+                3000, "Little Demetrius", "lilDee@gmail.com", 1000
26
+        )));
27
+
28
+        accounts.put(4000, new PremiumAccount(new AccountData(
29
+                4000, "Big Demetrius", "bigDee@gmail.com", 100000
30
+        )));
23 31
     }
24 32
 
25 33
     public ActionResult<AccountData> getAccountById(int id) {
@@ -32,14 +40,14 @@ public class Bank {
32 40
         }
33 41
     }
34 42
 
35
-    public ActionResult<AccountData> deposit(AccountData accountData, int amount) {
43
+    public ActionResult<AccountData> deposit(AccountData accountData, double amount) {
36 44
         Account account = accounts.get(accountData.getId());
37 45
         account.deposit(amount);
38 46
 
39 47
         return ActionResult.success(account.getAccountData());
40 48
     }
41 49
 
42
-    public ActionResult<AccountData> withdraw(AccountData accountData, int amount) {
50
+    public ActionResult<AccountData> withdraw(AccountData accountData, double amount) {
43 51
         Account account = accounts.get(accountData.getId());
44 52
         boolean ok = account.withdraw(amount);
45 53
 

+ 1
- 1
src/main/java/rocks/zipcode/atm/bank/PremiumAccount.java View File

@@ -12,7 +12,7 @@ public class PremiumAccount extends Account {
12 12
     }
13 13
 
14 14
     @Override
15
-    protected boolean canWithdraw(int amount) {
15
+    protected boolean canWithdraw(double amount) {
16 16
         return getBalance() + OVERDRAFT_LIMIT >= amount;
17 17
     }
18 18
 }