Class SavingsAccount

java.lang.Object
  extended by BankAccount
      extended by SavingsAccount
All Implemented Interfaces:
HasBalance

public class SavingsAccount
extends BankAccount

A savings account retains all the features of a bank account. However, if the balance is below a minimum balance, withdraws are not permitted. Furthermore, annual interest is deposited to the account at a specified interest rate. The minimum balance for this savings account is $1000.


Constructor Summary
SavingsAccount()
          Creates a savings account with initial balance equal to the minimum balance and interest rate equal to 2%.
SavingsAccount(double balance, double interestRate)
          Creates a savings account with the given initial balance and interest rate.
 
Method Summary
 void depositInterest()
          Deposits annual interest to the account according to the interest rate.
 boolean equals(java.lang.Object o)
          Checks whether two savings accounts are equal.
 void printBalance()
          Prints the balance of the savings account.
 boolean withdraw(double amount)
          Performs the withdrawal and returns true if the final balance is greater than the minimum balance, otherwise leaves balance unchanged and returns false.
 
Methods inherited from class BankAccount
deposit, getAccountNumber, getBalance, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SavingsAccount

public SavingsAccount(double balance,
                      double interestRate)
Creates a savings account with the given initial balance and interest rate.

Parameters:
balance - Initial balance
interestRate - Interest rate

SavingsAccount

public SavingsAccount()
Creates a savings account with initial balance equal to the minimum balance and interest rate equal to 2%.

Method Detail

depositInterest

public void depositInterest()
Deposits annual interest to the account according to the interest rate.


withdraw

public boolean withdraw(double amount)
Performs the withdrawal and returns true if the final balance is greater than the minimum balance, otherwise leaves balance unchanged and returns false.

Specified by:
withdraw in class BankAccount
Parameters:
amount - Withdrawal amaount
Returns:
True if successful, false if unsuccessful

equals

public boolean equals(java.lang.Object o)
Checks whether two savings accounts are equal. They are equal if their balances are equal, and their interest rates are equal.

Overrides:
equals in class BankAccount
Parameters:
o - Object to be compared
Returns:
True if equal, false otherwise

printBalance

public void printBalance()
Prints the balance of the savings account.