|
|
@@ -1,5 +1,7 @@
|
|
1
|
1
|
package rocks.zipcode.atm.bank;
|
|
2
|
2
|
|
|
|
3
|
+import javafx.scene.control.Alert;
|
|
|
4
|
+import javafx.scene.control.ButtonType;
|
|
3
|
5
|
import rocks.zipcode.atm.ActionResult;
|
|
4
|
6
|
|
|
5
|
7
|
import java.awt.event.ActionEvent;
|
|
|
@@ -45,11 +47,20 @@ public class Bank {
|
|
45
|
47
|
}
|
|
46
|
48
|
|
|
47
|
49
|
public ActionResult<AccountData> withdraw(AccountData accountData, float amount) {
|
|
|
50
|
+ // this gets the ID from accountdata and then gets the account in the hashmap
|
|
48
|
51
|
Account account = accounts.get(accountData.getId());
|
|
49
|
52
|
boolean ok = account.withdraw(amount);
|
|
50
|
53
|
|
|
51
|
54
|
if (ok) {
|
|
|
55
|
+
|
|
|
56
|
+ if (account.getBalance() < 0) {
|
|
|
57
|
+ Alert overDraftAlert = new Alert(Alert.AlertType.INFORMATION);
|
|
|
58
|
+ overDraftAlert.setContentText("This transaction will overdraft your account.");
|
|
|
59
|
+ overDraftAlert.showAndWait();
|
|
|
60
|
+ }
|
|
|
61
|
+
|
|
52
|
62
|
return ActionResult.success(account.getAccountData());
|
|
|
63
|
+
|
|
53
|
64
|
} else {
|
|
54
|
65
|
return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
|
|
55
|
66
|
}
|