Main.Lab12 History
Hide minor edits - Show changes to markup
April 19, 2010, at 10:16 AM MST
by -
Changed line 9 from:
add(account)- add the given account instance (can be either aCheckingAccountor a @@SavingsAccount).
to:
add(account)- add the given account instance (can be either aCheckingAccountor aSavingsAccount).
April 19, 2010, at 10:16 AM MST
by -
Changed line 11 from:
pay_interest()- pay interest to allSavingsAccountinstances. How to tell if a given account is aSavingsAccount? One way is to check the name of the class usingaccount.__class__.__name__. Another is to simply check if the account instance has apay_interestmethod using thehasattrfunction. See http://docs.python.org/library/functions.html#hasattr A third option is to put a call to an account'spay_interestmethod in atry:block and ignore the exception if it happens.
to:
pay_interest()- pay interest to allSavingsAccountinstances. How to tell if a given account is aSavingsAccount? One way is to check the name of the class usingaccount.__class__.__name__. Another is to simply check if the account instance has apay_interestmethod using thehasattrfunction. See http://docs.python.org/library/functions.html#hasattr A third option is to put a call to an account'spay_interestmethod in atry: except:block and ignore the exception if it happens.
April 19, 2010, at 10:15 AM MST
by -
Changed lines 11-12 from:
pay_interest()- pay interest to allSavingsAccountinstances. How to tell if a given account is aSavingsAccount? One way is to check the name of the class usingaccount.__class__.__name__. Another is to simply check if the account instance has apay_interestmethod using thehasattrfunction. See http://docs.python.org/library/functions.html#hasattr
A third option is to put a call to an account's pay_interest method in a try: block and ignore the exception if it happens.
to:
pay_interest()- pay interest to allSavingsAccountinstances. How to tell if a given account is aSavingsAccount? One way is to check the name of the class usingaccount.__class__.__name__. Another is to simply check if the account instance has apay_interestmethod using thehasattrfunction. See http://docs.python.org/library/functions.html#hasattr A third option is to put a call to an account'spay_interestmethod in atry:block and ignore the exception if it happens.
April 19, 2010, at 10:15 AM MST
by -
Added lines 1-14:
Lab 12
More object oriented programming
In lab 11 we created some classes to deal with bank accounts. In this lab we will create a class called Bank that stores bank accounts.
Your Bank class should support the following methods:
add(account)- add the given account instance (can be either aCheckingAccountor a @@SavingsAccount).close(account_number)- close the account with the given numberpay_interest()- pay interest to allSavingsAccountinstances. How to tell if a given account is aSavingsAccount? One way is to check the name of the class usingaccount.__class__.__name__. Another is to simply check if the account instance has apay_interestmethod using thehasattrfunction. See http://docs.python.org/library/functions.html#hasattr
A third option is to put a call to an account's pay_interest method in a try: block and ignore the exception if it happens.
total_balance()- returns the total balance in all the bank's accounts.__len__()- returns the number of accounts in the bank
