Lecture notes for Computer Science I by James Tam | Return to the course web page |
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).
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.
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. |