Class BankAccount

java.lang.Object
  extended by BankAccount

public class BankAccount
extends java.lang.Object


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.
 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]
 boolean withdraw(double amount)
          Withdraws the given amount from the account and returns true if the resulting balance is positive.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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 boolean withdraw(double amount)
Withdraws the given amount from the account and returns true if the resulting balance is positive. Leaves the account balance unchanged and returns false if the resulting balance would be negative.

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

getBalance

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

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