package com.accenture.multibank.factory;

import com.accenture.multibank.accounts.AccountModifiable;
import com.accenture.multibank.accounts.AccountType;
import com.accenture.multibank.accounts.CreditAccount;
import com.accenture.multibank.accounts.SavingAccount;
import com.accenture.multibank.exceptions.OperationNotSupportedException;
import com.accenture.multibank.generator.AccountNumberGenerator;

public class SimpleAccountFactory implements AccountFactory {

	/**
	 * Creates an account with the account number generated by the given generator
	 * @param generator Generator wo be used to generate the account number
	 * @param accountType Type of the account
	 * @param balance Balance to be set on the account
	 * @return
	 */
	public AccountModifiable createAccount(AccountNumberGenerator generator, AccountType accountType, int balance) throws OperationNotSupportedException {
		int accNum = generator.generateAccountNumber();
		AccountModifiable acc = null;

		switch (accountType) {
			case SAVING:
				acc = new SavingAccount(accNum, balance);
				break;
			case CREDIT:
				acc = new CreditAccount(accNum, balance);
				break;
			default:
				throw new OperationNotSupportedException("Account type not supported yet");
		}

		return acc;
	}

}

package com.accenture.multibank.factory;

import com.accenture.multibank.accounts.AccountModifiable;
import com.accenture.multibank.accounts.AccountType;
import com.accenture.multibank.accounts.CreditAccount;
import com.accenture.multibank.accounts.SavingAccount;
import com.accenture.multibank.exceptions.OperationNotSupportedException;
import com.accenture.multibank.generator.AccountNumberGenerator;

public class SimpleAccountFactory implements AccountFactory {

	/**
	 * Creates an account with the account number generated by the given generator
	 * @param generator Generator wo be used to generate the account number
	 * @param accountType Type of the account
	 * @param balance Balance to be set on the account
	 * @return
	 */
	public AccountModifiable createAccount(AccountNumberGenerator generator, AccountType accountType, int balance) throws OperationNotSupportedException {
		if (generator == null)
			throw new NullPointerException("Generator can't be null");
		if (accountType == null)
			throw new NullPointerException("Account type not specified");

		int accNum = generator.generateAccountNumber();
		AccountModifiable acc = null;

		switch (accountType) {
			case SAVING:
				acc = new SavingAccount(accNum, balance);
				break;
			case CREDIT:
				acc = new CreditAccount(accNum, balance);
				break;
			default:
				throw new OperationNotSupportedException("Account type not supported yet");
		}

		return acc;
	}

}

add exception handling when either generator or account type is null