Class SimpleBankAccount

java.lang.Object
  extended by SimpleBankAccount

public class SimpleBankAccount
extends java.lang.Object


Constructor Summary
SimpleBankAccount()
          Creates a bank account with initial balance 0 and account number 1.
SimpleBankAccount(double initBalance, int accountNumber)
          Creates a bank account with the given initial balance and given account number.
SimpleBankAccount(SimpleBankAccount b)
          Copy constructor
 
Method Summary
 void deposit(double amount)
          Deposits the given amount to the account.
 boolean equals(java.lang.Object o)
          Tests whether the given object is equal to this object.
 int getAccountNumber()
          Returns the account number.
 double getBalance()
          Returns the account balance.
 java.lang.String toString()
          Returns a string representation of the object.
 int withdraw(double amount)
          Withdraws the given amount from the account, as long as sufficient funds are available.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleBankAccount

public SimpleBankAccount()
Creates a bank account with initial balance 0 and account number 1.


SimpleBankAccount

public SimpleBankAccount(double initBalance,
                         int accountNumber)
Creates a bank account with the given initial balance and given account number.

Parameters:
initBalance - Intial balance
accountNumber - Account number

SimpleBankAccount

public SimpleBankAccount(SimpleBankAccount b)
Copy constructor

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 to be deposited

getAccountNumber

public int getAccountNumber()
Returns the account number.

Returns:
Account number

getBalance

public double getBalance()
Returns the account balance.

Returns:
Account balance

withdraw

public int withdraw(double amount)
Withdraws the given amount from the account, as long as sufficient funds are available. The amount is withdrawn if the balance is greater than or equal to the amount; otherwise, nothing happens. The return value is 0 if the withdraw was successful, and 1 otherwise.

Parameters:
amount - Amount to be withdrawn
Returns:
Error code: 0 if successful, 1 if unsuccessful

toString

public java.lang.String toString()
Returns a string representation of the object. Example for an object created with the default constructor: [SimpleBankAccount:balance=0,accountNumber=1]

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

equals

public boolean equals(java.lang.Object o)
Tests whether the given object is equal to this object.

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