
import java.util.*;

/**
 * Representation for a customer of the bank.  In this implementation, a given
 * customer can have only one account of each type (checking and savings).
 * 
 * @author Russell C. Bjork
 * @version November 18, 2009
 */

public class Customer
{
    private String name;
    private CheckingAccount checkingAccount;    // null if none
    private SavingsAccount savingsAccount;      // null if none
 
    /**
     * Constructor for objects of class Customer
     * 
     * @param name the customer's name
     */
    public Customer(String name)
    {
        this.name = name;
    }
    
    /**
     * Add an account to list of accounts owned by customer
     * 
     * @param account the account to be added
     */
    public void addAccount(BankAccount account)
    {
        if (account instanceof CheckingAccount)
            checkingAccount = (CheckingAccount) account;
        else if (account instanceof SavingsAccount)
            savingsAccount = (SavingsAccount) account;
    }
    
    /**
     * Print out information on all accounts owned by customer
     */
    public void printAccounts()
    {
        System.out.println("Account information for: " + name);
        if (checkingAccount != null)
            System.out.println("Checking account " + 
                checkingAccount.getAccountNumber() + " " + 
                checkingAccount.reportBalance());
        if (savingsAccount != null)
            System.out.println("Savings account " + 
                savingsAccount.getAccountNumber() + " " + 
                savingsAccount.reportBalance());
        System.out.println("End of information for: " + name);
        System.out.println();
    }
    
    /** Accessor for the checking account owned by this customer
     * 
     *  @return the checking account - null if none
     */
    public CheckingAccount getCheckingAccount()
    {
        return checkingAccount;
    }

    /** Accessor for the savings account owned by this customer
     * 
     *  @return the savings account - null if none
     */
    public SavingsAccount getSavingsAccount()
    {
        return savingsAccount;
    }

}
