/** Class represents savings accounts 
 *
 * @author Tony Gaddis - Updated by N Harris
 * @version V2 - 03/13/07
 */
public class SavingsAccount extends BankAccount
{
	/** interest rate paid on this savings account */
	private double rate;	//annual rate
	
	/** sequence number for this savings account */
	private int savingsNumber;
	
	/** the accountNumber for this SavingsAccount */
	private String accountNumber;
	
	/** Explicit value constructor to make a new Savings Account
	 *
	 * @param name The name of the person owning this account
	 * @param begBal The initial balance on this account
	 */
	public SavingsAccount(String name, double begBal)
	{
		super(name, begBal);
		
		rate = .025; // current annual rate
		savingsNumber = 0; // assume this is the first account
		
		// build account number
		accountNumber = super.getAccountNumber() + "-" + savingsNumber;
	}
	/** Copy constructor to build a new account based on an old account
	 *
	 * @param oldAccount The account we are using to build from
	 * @param begBal The starting balance for this new account
	 */	
	public SavingsAccount(SavingsAccount oldAccount, double begBal)
	{
		super(oldAccount, begBal);
	
		// increment account number by one
		savingsNumber = oldAccount.savingsNumber + 1;
		
		// and use to build new account number
		accountNumber = super.getAccountNumber() + "-" + savingsNumber;
	} 
	
	/** Method posts the monthly interest updating the account balance
	 */
	public void postInterest( )
	{
		//rate is an annual rate, and we only one one month's worth of interest.
		double newBalance;
		
		newBalance = getBalance() * (1 + rate / 12);
		
		setBalance(newBalance);
	}
	
	/** gets the account number from this account
	 *
	 * @return A String representing the account number
	 */ 
	public String getAccountNumber( )
	{
		return accountNumber;	
	}
}