Class BankAccount

java.lang.Object
  extended by BankAccount
All Implemented Interfaces:
HasBalance
Direct Known Subclasses:
CheckingAccount, SavingsAccount

public abstract class BankAccount
extends java.lang.Object
implements HasBalance


Constructor Summary
BankAccount()
          Creates a bank account with initial balance of zero.
BankAccount(BankAccount b)
          Copy constructor -- creates a bank account that is a copy of the existing bank account
BankAccount(double balance)
          Creates a bank account with the given balance.
 
Method Summary
 void deposit(double amount)
          Deposits the given amount to the account.
 boolean equals(java.lang.Object o)
          Checks to see if two bank accounts are equal.
 int getAccountNumber()
          Returns the account number.
 double getBalance()
          Returns the current balance of the account.
 java.lang.String toString()
          Transforms the class into a string of the following form (for example, if the balance is 10.56): [BankAccount:balance=10.56]
abstract  boolean withdraw(double amount)
          Withdraws money from the account.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface HasBalance
printBalance
 

Constructor Detail

BankAccount

public BankAccount(double balance)
Creates a bank account with the given balance.

Parameters:
balance - Initial balance for the account

BankAccount

public BankAccount()
Creates a bank account with initial balance of zero.


BankAccount

public BankAccount(BankAccount b)
Copy constructor -- creates a bank account that is a copy of the existing bank account

Parameters:
b - Bank account to be copied
Method Detail

deposit

public void deposit(double amount)
Deposits the given amount to the account.

Parameters:
amount - Amount of the deposit

withdraw

public abstract boolean withdraw(double amount)
Withdraws money from the account. The behaviour of the withdraw method is customized for each type of bank account.

Parameters:
amount - Amount of the withdrawal
Returns:
True if successful, false if unsuccessful

getBalance

public double getBalance()
Returns the current balance of the account.

Specified by:
getBalance in interface HasBalance
Returns:
Current balance of the account

toString

public java.lang.String toString()
Transforms the class into a string of the following form (for example, if the balance is 10.56): [BankAccount:balance=10.56]

Overrides:
toString in class java.lang.Object
Returns:
String representation of the class

equals

public boolean equals(java.lang.Object o)
Checks to see if two bank accounts are equal.

Overrides:
equals in class java.lang.Object
Parameters:
o - Bank account to check for equality
Returns:
True if equal, false otherwise

getAccountNumber

public int getAccountNumber()
Returns the account number. Each account gets a unique account number, assigned in the order the accounts are created: the first account gets account number 1, the second gets account number 2, and so on.

Returns:
Account number