Main.Lab12 History
Hide minor edits - Show changes to markup
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 aSavingsAccount).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'spay_interestmethod in atry: except: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
Inheritance.
You are asked to write software for a bank that represents two types of bank accounts - checking accounts and savings accounts. We'll discuss the differences between the two types of accounts and the methods/data they need to have. As both types of accounts share functionality, we will use inheritance to capture that common functionality.
add(account)- add the given account instance (can be either aCheckingAccountor a @@SavingsAccount).
add(account)- add the given account instance (can be either aCheckingAccountor aSavingsAccount).
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.
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.
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.
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.
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
