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 a CheckingAccount or a SavingsAccount).
  • close(account_number) - close the account with the given number
  • pay_interest() - pay interest to all SavingsAccount instances. How to tell if a given account is a SavingsAccount? One way is to check the name of the class using account.__class__.__name__. Another is to simply check if the account instance has a pay_interest method using the hasattr function. 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: 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