Main.Lab12 History

Hide minor edits - Show changes to markup

April 19, 2010, at 10:16 AM MST by 10.84.44.72 -
Changed line 9 from:
  • add(account) - add the given account instance (can be either a CheckingAccount or a @@SavingsAccount).
to:
  • add(account) - add the given account instance (can be either a CheckingAccount or a SavingsAccount).
April 19, 2010, at 10:16 AM MST by 10.84.44.72 -
Changed line 11 from:
  • 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: block and ignore the exception if it happens.
to:
  • 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.
April 19, 2010, at 10:15 AM MST by 10.84.44.72 -
Changed lines 11-12 from:
  • 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: block and ignore the exception if it happens.

to:
  • 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: block and ignore the exception if it happens.
April 19, 2010, at 10:15 AM MST by 10.84.44.72 -
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 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: 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