Package account :: Module account :: Class Account
[hide private]
[frames] | no frames]

Class Account

object --+
         |
        Account

The class Account represents accounts in a simple (unrealistic) banking system.

Instance Methods [hide private]
 
__init__(self, owner, interest_rate)
Creates a new account of the given customer.
customer object
get_owner(self)
Returns the customer who owns the account.
float
get_balance(self)
Returns the current balance of the account.
 
deposit(self, amount)
Deposits the given sum onto the account, assuming the given value is positive.
float
withdraw(self, amount)
Tries to withdraw the given sum from the account, assuming the given amount is positive.
boolean
transfer_to(self, another_account, amount)
Transfers the given sum from this account to another given account, assuming that there is sufficient money available in this account.
float
get_interest_rate(self)
Returns the interest rate of the account
 
set_interest_rate(self, interest_rate)
Sets the interest rate of the account to a new value.
 
add_interest(self)
Adds interest to the account according to the account's interest rate.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, owner, interest_rate)
(Constructor)

 

Creates a new account of the given customer. The new account has a given interest rate and a zero balance.

Parameters:
  • owner (customer object) - the customer whose account is being created
  • interest_rate (float) - the interest rate of the new account, e.g. 0.05 means a 5% interest rate
Overrides: object.__init__

get_owner(self)

 

Returns the customer who owns the account.

Returns: customer object
account owner

get_balance(self)

 

Returns the current balance of the account.

Returns: float
account balance

deposit(self, amount)

 

Deposits the given sum onto the account, assuming the given value is positive. Otherwise, does nothing.

Parameters:
  • amount (float) - the amount to deposit

withdraw(self, amount)

 

Tries to withdraw the given sum from the account, assuming the given amount is positive. If the given amount is higher than the account's current balance, only the money currently available on the account is withdrawn. If the given amount is negative, returns 0.

Parameters:
  • amount (float) - the amount to withdraw
Returns: float
the amount of money successfully withdrawn from the account

transfer_to(self, another_account, amount)

 

Transfers the given sum from this account to another given account, assuming that there is sufficient money available in this account. If not, no transfer is made at all.

Parameters:
  • another_account (account object) - the account the money is deposited in
  • amount (float) - the amount to transfer to the given account
Returns: boolean
a value indicating if the transfer was successful

get_interest_rate(self)

 

Returns the interest rate of the account

Returns: float
interest rate

set_interest_rate(self, interest_rate)

 

Sets the interest rate of the account to a new value. If the given value is negative, the interest rate is set to zero instead.

Parameters:
  • interest_rate (float) - the new interest rate of the account, e.g. 0.05 means a 5% interest rate

add_interest(self)

 

Adds interest to the account according to the account's interest rate. E.g. if the interest rate is set to 0.05, adds 5% of the account's balance to the account.