//import rocks.zipcode.atm.ActionResult; import java.util.HashMap; import java.util.Map; /** * @author ZipCodeWilmington */ public class Bank { private Map 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 ))); } public ActionResult 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 or 2000"); } } public ActionResult deposit(AccountData accountData, int amount) { Account account = accounts.get(accountData.getId()); account.deposit(amount); return ActionResult.success(account.getAccountData()); } public ActionResult withdraw(AccountData accountData, int amount) { Account account = accounts.get(accountData.getId()); boolean ok = account.withdraw(amount); if (ok) { return ActionResult.success(account.getAccountData()); } else { return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance()); } } }