/**
 * Representation for a bank account.
 * 
 * @author Russell C. Bjork 
 * @version January 9, 2003
 */
public class BankAccount
{
    private int accountNumber;
    private Customer owner;
    private int currentBalance;        // Number of cents
    
    /**
     * Constructor for objects of class BankAccount
     * 
     * @param owner the owner of this account
     * 
     * The account number will be set to the first available unused number
     * The balance will be set to zero
     */
    public BankAccount(Customer owner)
    {
        this.accountNumber = nextAccountNumber ++;
        this.owner = owner;
        owner.addAccount(this);
        currentBalance = 0;
    }

    /**
     * Deposit money
     * 
     * @param amount the amount to deposit (in cents)
     */
    public void deposit(int amount)
    {
        currentBalance += amount;
    }
    
    /**
     * Withdraw money
     * 
     * @param amount the amount to withdraw (in cents)
     * @exception IllegalArgumentException if insufficient balance on hand
     */
    public void withdraw(int amount)
    {
        if (currentBalance < amount)
            throw new IllegalArgumentException();
        currentBalance -= amount;
    }
    
    /**
     * Calculate interest - for now, assume non interest-bearing
     *
     *	@return the calculated interest
     */
    public int calculateInterest()
    {
    	return 0;
    }
    
    /** Report current balance.  Amount is formatted neatly as dollars and
     *  cents, with a dollar sign and decimal point
     */
    public String reportBalance()
    {
        String result = "$" + currentBalance/100 + ".";
        int cents = currentBalance % 100;
        if (cents < 10)
            result += "0";
        result += cents;
        return result;
    }
    
    /** Accessor for account number
     * 
     * @return account number for this account
     */
    int getAccountNumber()
    {
        return accountNumber;
    }
    
    /** Next available account number to assign */
    
    private static int nextAccountNumber = 1;
}
