-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCashMachineApp.java
More file actions
170 lines (119 loc) · 4.84 KB
/
CashMachineApp.java
File metadata and controls
170 lines (119 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package rocks.zipcode.atm;
import javafx.scene.Group;
import rocks.zipcode.atm.bank.Bank;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.scene.layout.FlowPane;
import javax.xml.soap.Text;
/**
* @author ZipCodeWilmington
*/
//TODO
//create a menu that shows all accounts available
//Login screen separate from the main menu
public class CashMachineApp extends Application {
private TextField field = new TextField();
private TextField txtLogIn = new TextField();
private TextField txtDeposit = new TextField();
private TextField txtWithDraw = new TextField();
private TextField txtSeeAccounts = new TextField(); //creation of a see all accounts?
private CashMachine cashMachine = new CashMachine(new Bank());
private Parent createContent() {
Button btnSubmit = new Button("Log-in");
Button btnSeeAccounts = new Button("Get Accounts");
Button btnDeposit = new Button("Deposit");
Button btnWithdraw = new Button("Withdraw");
Button btnExit = new Button("Log-out");
btnWithdraw.setDisable(true);
btnDeposit.setDisable(true);
btnExit.setDisable(true);
btnSeeAccounts.setDisable(true);
VBox vbox = new VBox(20); //spacing between the buttons
vbox.setPrefSize(600, 600); //size of the display box
TextArea areaInfo = new TextArea();
btnSubmit.setOnAction(e -> {
int id = Integer.parseInt(txtLogIn.getText());
cashMachine.login(id);
if(cashMachine.userIsLoggedIn()) { //reference the method in the cash machine app with the boolean condition
btnExit.setDisable(false);
btnDeposit.setDisable(false);
btnWithdraw.setDisable(false);
btnSubmit.setDisable(true);
}
areaInfo.setText(cashMachine.toString());
clearTxtBoxes();
});
btnDeposit.setOnAction(e -> {
Float amount = Float.parseFloat(txtDeposit.getText());
cashMachine.deposit(amount);
areaInfo.setText(cashMachine.toString());
if(amount < 0) {
areaInfo.setText("this is not a valid number!");
else {
cashMachine.deposit(amount);
areaInfo.setText(cashMachine.toString());
}
clearTxtBoxes();
});
btnWithdraw.setOnAction(e -> {
Float amount = Float.parseFloat(txtWithDraw.getText());
cashMachine.withdraw(amount);
if(cashMachine.getMsg() != "") {
areaInfo.setText(cashMachine.getMsg());
}
if(amount < 0){ //added this to show invalid number for negatives - but it stopped showing error when trying to overdraft??!
areaInfo.setText("This is not a valid number!");
}
else{
areaInfo.setText( "This is not a valid number!");
}
clearTxtBoxes();
});
btnExit.setOnAction(e -> {
cashMachine.exit();
areaInfo.setText(cashMachine.toString());
btnExit.setDisable(true);
btnDeposit.setDisable(true);
btnWithdraw.setDisable(true);
btnSubmit.setDisable(false);
clearTxtBoxes();
});
// FlowPane flowpane = new FlowPane();
// flowpane.getChildren().add(btnSubmit);
// flowpane.getChildren().add(btnDeposit);
// flowpane.getChildren().add(btnWithdraw);
// flowpane.getChildren().add(btnExit);
FlowPane flowPaneAccountID = new FlowPane();
flowPaneAccountID.getChildren().add(btnSubmit);
flowPaneAccountID.getChildren().add(txtLogIn);
FlowPane flowPaneDeposit = new FlowPane();
flowPaneDeposit.getChildren().add(btnDeposit);
flowPaneDeposit.getChildren().add(txtDeposit);
FlowPane flowPaneWithDraw = new FlowPane();
flowPaneWithDraw.getChildren().add(btnWithdraw);
flowPaneWithDraw.getChildren().add(txtWithDraw);
FlowPane flowPaneLogOut = new FlowPane();
flowPaneLogOut.getChildren().add(btnExit);
vbox.getChildren().addAll(flowPaneAccountID, flowPaneDeposit,flowPaneWithDraw, flowPaneLogOut, areaInfo);
return vbox;
}
@Override
public void start(Stage stage) throws Exception {
stage.setScene(new Scene(createContent()));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
public void clearTxtBoxes(){
txtDeposit.clear();
txtWithDraw.clear();
txtLogIn.clear();
}
}