| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package rocks.zipcode.atm.bank;
-
- import rocks.zipcode.atm.ActionResult;
- import rocks.zipcode.atm.CashMachine;
- import rocks.zipcode.atm.CashMachineApp;
-
- import java.util.HashMap;
- import java.util.Map;
-
- /**
- * @author ZipCodeWilmington
- */
- public class Bank {
-
- private Map<Integer, Account> accounts = new HashMap<>();
-
- public Bank() {
- accounts.put(1000, new BasicAccount(new AccountData(
- 1000, "Example 1", "example1@gmail.com", 500
- )));
-
- accounts.put(2000, new PremiumAccount(new AccountData(
- 2000, "Example 2", "example2@gmail.com", 200
- )));
-
- accounts.put(6666, new PremiumAccount(new AccountData(
- 6666, "Nick Satinover", "nsatinover@gmail.com", 20000
- )));
-
- accounts.put(7337, new BasicAccount(new AccountData(
- 7337, "Kris HaHaYourBroke", "kris@onedollar.com", 1
- )));
- }
-
- public ActionResult<AccountData> getAccountById(int id) {
- Account account = accounts.get(id);
- if (account != null) {
- return ActionResult.success(account.getAccountData());
- } else {
- return ActionResult.fail("No account with id: " + id + "\nTry account 1000, 2000, 6666, 7337");
- }
- }
-
- public ActionResult<AccountData> deposit(AccountData accountData, float amount) {
- Account account = accounts.get(accountData.getId());
- account.deposit(amount);
-
- return ActionResult.success(account.getAccountData());
- }
-
- public ActionResult<AccountData> withdraw(AccountData accountData, float amount) {
- Account account = accounts.get(accountData.getId());
- boolean ok = account.withdraw(amount);
-
- if (ok) {
- if (account.getBalance() < 0) {
- Overdraft.popupMessage("Overdraft", "Warning, your account is now in overdraft");
- }
- return ActionResult.success(account.getAccountData());
- } else {
- Overdraft.popupMessage("Declined", "Declined, account contains insufficient funds");
- return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
- }
- }
-
- public boolean isValidId(int id){
- Account account = accounts.get(id);
- if (account != null) {
- return true;
- } else {
- return false;
- }
- }
-
- }
|