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

Class Account

source code

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.
source code
 
get_owner(self)
Returns the customer who owns the account.
source code
 
get_balance(self)
Returns the current balance of the account.
source code
 
deposit(self, amount)
Deposits the given sum onto the account, assuming the given value is positive.
source code
 
withdraw(self, amount)
Tries to withdraw the given sum from the account, assuming the given amount is positive.
source code
 
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.
source code
 
get_interest_rate(self)
Returns the interest rate of the account
source code
 
set_interest_rate(self, interest_rate)
Sets the interest rate of the account to a new value.
source code
 
add_interest(self)
Adds interest to the account according to the account's interest rate.
source code

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)

source code 

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

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

get_owner(self)

source code 

Returns the customer who owns the account.

Returns:
account owner

get_balance(self)

source code 

Returns the current balance of the account.

Returns:
account balance

deposit(self, amount)

source code 

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

Parameters:
  • amount - the amount to deposit

withdraw(self, amount)

source code 

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 - the amount to withdraw
Returns:
the amount of money successfully withdrawn from the account

transfer_to(self, another_account, amount)

source code 

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 - the account the money is deposited in
  • amount - the amount to transfer to the given account
Returns:
a boolean value indicating if the transfer was successful

get_interest_rate(self)

source code 

Returns the interest rate of the account

Returns:
interest rate

set_interest_rate(self, interest_rate)

source code 

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 - the new interest rate of the account, e.g. 0.05 means a 5% interest rate

add_interest(self)

source code 

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.