In Class: Week 11 Tuesday and Thursday:
Defining Classes


Create a week 11 subdirectory in your cs21/inclass directory by running update21:

$ update21
$ cd
$ cd cs21/class/w11-classes

Topics


In-class work

    Classes

  1. Open up accounts.py. Read through the mostly completed class definition for a bank account. Using this class will be able to define Account objects.

  2. First, we will illustrate the use of several functions. You should be able to draw a stack diagram for the constructor showing how self is defined.

  3. Open up testAccounts.py and trace the code which creates three separate Account objects using the constructor, prints them using the string conversion method, and prints out information given by the accessor methods getBalance and getName

  4. Take some time to implement and test the changePin method. It is very important that you employ unit testing just as you did with the top-down design labs

  5. When you are finished, analyze and test the withdraw() function. Once you understand how that works, implement and test the deposit() method. If you have time, implement and test the computeInterest() method.

  6. With the time remaining (possible into next week), we will rethink how object-oriented programming could improve our Scattergories program from Week 7. Specifically, we will define a class for creating card objects that store the categories and answers for a user.

Post-class questions