ZipCloudBank's meh banking app.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //import rocks.zipcode.atm.ActionResult;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. /**
  5. * @author ZipCodeWilmington
  6. */
  7. public class Bank {
  8. private Map<Integer, Account> accounts = new HashMap<>();
  9. public Bank() {
  10. accounts.put(1000, new BasicAccount(new AccountData(
  11. 1000, "Example 1", "example1@gmail.com", 500
  12. )));
  13. accounts.put(2000, new PremiumAccount(new AccountData(
  14. 2000, "Example 2", "example2@gmail.com", 200
  15. )));
  16. }
  17. public ActionResult<AccountData> getAccountById(int id) {
  18. Account account = accounts.get(id);
  19. if (account != null) {
  20. return ActionResult.success(account.getAccountData());
  21. } else {
  22. return ActionResult.fail("No account with id: " + id + "\nTry account 1000 or 2000");
  23. }
  24. }
  25. public ActionResult<AccountData> deposit(AccountData accountData, int amount) {
  26. Account account = accounts.get(accountData.getId());
  27. account.deposit(amount);
  28. return ActionResult.success(account.getAccountData());
  29. }
  30. public ActionResult<AccountData> withdraw(AccountData accountData, int amount) {
  31. Account account = accounts.get(accountData.getId());
  32. boolean ok = account.withdraw(amount);
  33. if (ok) {
  34. return ActionResult.success(account.getAccountData());
  35. } else {
  36. return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
  37. }
  38. }
  39. }