Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bank;
- import java.util.HashMap;
- public class Bank {
- private static Bank bank;
- HashMap<String, Account> Accounts = new HashMap<String, Account>();
- int accountNumber;
- private Bank() {}
- public static Bank getBank() {
- if(bank == null) bank = new Bank();
- return bank;
- }
- public Account createAccount() {
- Accounts.put(++accountNumber + "", new Account(accountNumber + ""));
- return Accounts.get(accountNumber + "");
- }
- public Account lookupAccount(String number) {
- return Accounts.get(number);
- }
- public int getBalance(String accountNo) throws AccountException {
- if (!Accounts.containsKey(accountNo)) throw new AccountException("Account " + accountNo + " doesn't exist");
- else return Accounts.get(accountNo).getBalance();
- }
- public void deposit(String accountNo, int howMuch) throws AccountException {
- if (!Accounts.containsKey(accountNo)) throw new AccountException("Account " + accountNo + " doesn't exist");
- else Accounts.get(accountNo).deposit(howMuch);
- }
- public void withdraw(String accountNo, int howMuch) throws AccountException {
- if (!Accounts.containsKey(accountNo)) throw new AccountException("Account " + accountNo + " doesn't exist");
- else Accounts.get(accountNo).withdraw(howMuch);
- }
- public void transfer(String sourceAccount, int howMuch, String targetAccount) throws AccountException {
- if (!Accounts.containsKey(sourceAccount)) throw new AccountException("Account " + sourceAccount + " doesn't exist");
- else if (!Accounts.containsKey(targetAccount)) throw new AccountException("Account " + targetAccount + " doesn't exist");
- else Accounts.get(sourceAccount).transfer(howMuch, Accounts.get(targetAccount));
- }
- public void closeAccount(String accountNo) throws AccountException {
- if (!Accounts.containsKey(accountNo)) throw new AccountException("Account " + accountNo + " doesn't exist");
- else Accounts.get(accountNo).closeAccount();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement