/**
 * A simple "bank" Account
 *
 * @version 1.0
 * @author  Prof. David Bernstein, James Madison University
 */
public class Account
{
    protected double balance;
    protected int    id;

    /**
     * Default constructor
     */
    public Account() 
    {

	balance = 0;
	id = -1;
    }

    /**
     * Explicit Value Constructor
     *
     * @param idNumber        The ID for the Account
     * @param initialDeposit  The initial deposit
     */
    public Account(int idNumber, double initialDeposit)
    {
	balance = 0;

	id = idNumber;
	if (initialDeposit > 0) balance = initialDeposit;
    }

    /**
     * Determine the maximum amount that can be withdrawn
     *
     * @return The size of the maximum possible withdrawal
     */
    public double amountAvailable()
    {
	return balance;
    }

    /**
     * Deposit money in this Account
     *
   * @param amount    The size of the deposit
   *
   * @return false if unable to deposit and true otherwise
   */
    public boolean deposit(double amount)
    {
	boolean ok;

	ok = false;
	if (amount >= 0) {

	    balance += amount;
	    ok = true;
	}

	return ok;
    }

    /**
     * Obtain the ID of this Account
     *
     * @return The ID of this Account
     */
    public int getID()
    {
	return id;
    }
  
    /**
     * Withdraw money from this Account
     *
     * @param amount   The size of the withdrawal
     *
     * @return false if unable to withdraw and true otherwise
     */
    public boolean withdraw(double amount)
    {
	boolean     ok;

	ok = false;
	if (amount >= 0) {

	    // Check if available funds are sufficient
	    // 
	    // Note: amountAvailble() is overriden in the 
	    // derived class OverdraftAccount.
	    // Which version of amountAvailable() will be 
	    // called?
	    //
	    if (amountAvailable() >= amount) {

		balance -= amount;
		ok = true;
	    }
	}

	return ok;
    }
}
