Class Account

java.lang.Object
  extended by Account

public class Account
extends java.lang.Object

A class for representing bank accounts.

Author:
R. Brown, 1/00

Field Summary
(package private)  long accountNumber
          Unique identifying number for an instance of Account.
(package private)  double balance
          Current balance in this instance of Account.
(package private)  double initialBalance
          Original balance when this instance of Account was constructed.
(package private) static long nextAccountNumber
          Lowest unused account number, for generating unique identifying numbers for instances of Account.
(package private)  java.lang.String owner
          Name of the owner of an instance of Account.
 
Constructor Summary
Account(java.lang.String name, double init_bal)
          Creates an instance of Account, with it's own account number.
 
Method Summary
 double deposit(double amount)
          Add an amount to the balance.
 long getAccountNumber()
          Retrieve the account number.
 double getBalance()
          Retrieve the current balance.
 double getInitialBalance()
          Retrieve the original balance.
 java.lang.String getOwner()
          Retrieve the owner.
 java.lang.String toString()
          Returns a string representation of this object.
 double withdraw(double amount)
          Remove an amount from the balance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nextAccountNumber

static long nextAccountNumber
Lowest unused account number, for generating unique identifying numbers for instances of Account.


balance

double balance
Current balance in this instance of Account.


initialBalance

double initialBalance
Original balance when this instance of Account was constructed.


accountNumber

long accountNumber
Unique identifying number for an instance of Account.


owner

java.lang.String owner
Name of the owner of an instance of Account.

Constructor Detail

Account

public Account(java.lang.String name,
               double init_bal)
Creates an instance of Account, with it's own account number.

Parameters:
name - The name of the owner
init_bal - The initial balance
Method Detail

getBalance

public double getBalance()
Retrieve the current balance.

Returns:
The value of the state variable balance

getInitialBalance

public double getInitialBalance()
Retrieve the original balance.

Returns:
The value of the state variable initialBalance

getAccountNumber

public long getAccountNumber()
Retrieve the account number.

Returns:
The value of the state variable accountNumber

getOwner

public java.lang.String getOwner()
Retrieve the owner.

Returns:
The value of the state variable owner

deposit

public double deposit(double amount)
Add an amount to the balance.

Parameters:
amount - Non-negative amount to add
Returns:
The resulting balance after addition
Throws:
java.lang.IllegalArgumentException - Thrown if amount is negative

withdraw

public double withdraw(double amount)
Remove an amount from the balance.

Parameters:
amount - Non-negative amount to subtract
Returns:
The resulting balance after subtraction
Throws:
java.lang.IllegalArgumentException - Thrown if amount is negative

toString

public java.lang.String toString()
Returns a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
A string showing the owner, account number, balance and initial balance for this instance of Account.