Lecture notes for Computer Science I by James Tam Return to the course web page

CPSC 231: Assignment 6

New Concepts to be applied for the assignment

The goal of this assignment is to give you a small feel for an alternate approach to writing programs. In most of your previous assignments your programs were subdivided into functions. This approach is known as the procedural approach to programming (a procedure is another name for a function). With the Object-Oriented approach your programs will be subdivided into objects and each object will consist of attributes (variables and constants) but unlike your previous assignment the object will also include methods (the Object-Oriented equivalent of a function).

Assignment description

The requirements for this assignment are identical to the ones for Assignment 2, except that you must now employ classes and class methods. Your program will consist of two classes  1) A "Driver" class (that contains the 'main' method)  2) Another class, "Fun", that implements the features described in the previous assignment.  In the assignment directory I have not only written the driver class for you but I have also created an outline of class fun. You need to use the code in these two modules for your assignment because it lays out the exact structure needed. All you have to do for this assignment is to decompose or divide the functionality of your previous assignment into methods of class Fun. The idea is to let you learn the mechanics of setting up a real (albeit small) Object-Oriented program. In order to get credit for this assignment your program must implement the methods listed below in the specified manner (method names, inputs, return values, functionality to be implemented by a function). Also note that these methods must be methods of the class Fun:

class Fun:

     def conclusion (self):

         print "The end"

They CANNOT be defined as regular functions (that are not part of a class definition):

class Fun:

     def introduction (self):

         print "yadda yadda yadda"

def conclusion ():            <= Not a method of class Fun, not allowed for this assignment.

     print "The end"

Finally note that in my definition of class Fun I have some constants defined as part of the class, as part of the style requirement for this assignment you should use them as needed.

Methods that MUST be implemented methods of class Fun (you won't get credit if they are not implemented as methods of the class)

Method name

Variable/variables passed as input1

Value returned

Description

calculateAddressModifier

address

addModifier

Given the address number, it will determine and return the address modifier.

calculateAgeModifier

age

ageModifier

Given the age, it will determine and return the age modifier.

determineFundex

ageModifier, addressModifier, petModifier

fundex

Given the information for the 3 modifiers, this method will determine and return the numeric fundex.

determinePetModifier

pet

petModifier

Given the pet information, it will determine and return the pet modifier.

displayFundex

fundex

nothing

Given the numeric fundex, this method will determine and display the fundex category. It should check and deal with for fundex values outside of the allowable ranges (too high or low).

getAddress

none

address

Prompt for and get as input the address number. It should also deal with an invalid address (set the modifier to the default).

getAge none age Prompt for and get as input the age. It should also deal with an invalid age (set the modifier to the default).
getPet none pet Prompt for and get as input the pet information.  It should check that the pet information is one of the allowable types and set the default as appropriate.
conclusion none none Displays a brief signoff to confirm to the user that he or she has quit the program.

1 This of course does not include the 'self' parameter which is syntactically required by Python in the definition of every class method.

Submitting your work:

  1. All of your source code/'dot-py' files ('driver.py', 'fun.py'...don't forget to submit them both especially the latter!) containing your Python program must be electronically submitted according to [the assignment submission requirements]. Since your program is quite small and the specifications are very specific you are not required to create a README file.
  2. As a reminder, you are not allowed to work in groups for this class. Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following [link].
  3. Before you submit your assignment to help make sure that you haven't missed anything here is a [checklist] of items to be used in marking.