Question
Python Computer Dating Date Profiles Class DateProfile Create a class called DateProfile that has the following instance attributes : gender - a single character string
Python Computer Dating
Date Profiles
Class DateProfile
Create a class called DateProfile that has the following instance attributes:
gender - a single character string, the gender of the applicant ('M' or 'F').
search_gender - single character string, the gender of desired partner ('M' or 'F'). This is not the gender of the applicant, but of the applicant's requested partner.
romance - an int from 1 to 10, indicating the importance of romance to the applicant.
finance - an int from 1 to 10, indicating the importance of finance to the applicant.
name - a string indicating the full name of the applicant.
Each object in the DateProfile class represents an applicant's profile. If the object is ('M', 'F', 7, 4, "Hugh Hefner") then the applicant's name is "Hugh Hefner", he's looking for a date who is Female, with romance being somewhat important (7) and finance being less important (4).
Create instended static constants for:
All range limits (like MIN_ROMANCE, MIN_NAME_LEN, etc.). These are the limits that the mutators test for.
All default values (like DEFAULT_GEND, DEFAULT_SEARCH_GEND, DEFAULT_NAME). These are used if the constructor without arguments is called or if arguments are supplied but a bad value (out-of-range) is detected. However, they are not used directly in the constructors, as we will find that there are helper methods that do the dirty work for the constructors -- see below.
You should supply all of the following instance methods of class DateProfile (at a minimum):
Accessors and Mutators for each attribute (instance member). For example: char get_gender() and bool set_gender(char gdr). In addition to individual mutators, create an instance method,set_all( ... ), that takes all five parameters and acts like a mutator, except that it does not return a boolean, i.e., in this one, you do not have to report bad parameters back to the user, even though you would still filter them out. Also, create an instance method, set_defaults(), that sets all five members to their default values.
Constructor that takes all 5 parameters, using default values when no arguments are passed. To avoid code duplication make sure the constructor utilizes the above mutators rather than do anything direct assignments or testing.
def fit_value(self, partner):, which returns a number from 0.0 (very bad fit) to 1.0 (perfect fit). The public instance method compares the calling object (self) to the object passed as a parameter. This method should call three helper methods determine_gender_fit( ... ), determine_romance_fit( ... ) and determine_finance_fit( ... ), that will be used to return intermediate results for each of the three factors. It should compute the final fit value that it returns by returning a 0 if gender is not compatible (regaredless of the other values) and return the average of finance and romance values if gender is compatible.
def determine_gender_fit(self, partner): This helper instance method returns either a 0 or 1 depending on the gender compatibility of the calling object and the passed parameter object. You have to compare gender compatibility completely: i.e., there must be mutual consent on this one! It is used by the public fit_value(), not directly by the client main.
def determine_romance_fit(self, partner): This helper instance method returns a number from (but not including) 0.0 to (and including) 1.0 depending on the romance compatibility of the calling object and the passed parameter object. The romance numbers should be highest (1.0) if the two values are equal (both 3, both 5, both 7) and lowest (perhaps a small non-zero value like .1) if their difference is 9. It is used by the public fit_value(), not directly by the client main.
def determine_finance_fit(self, partner): This helper instance method returns a number from (but not including) 0.0 to (and including) 1.0 depending on the finance compatibility of the calling object and the passed parameter object. The finance numbers should be highest (1.0) if the two values are equal (both 3, both 5, both 7) and lowest (perhaps a small non-zero value like .1) if their difference is 9. It is used by the public fit_value(), not directly by the client main.
def __str__(self) and to_string(self): Both the standard Python stringizer and a helper to_string() method that can be used by __str__() and/or called explicitly by the client as an alternative to using __str__().
You should supply all of the following class or static methods of class DateProfile (at a minimum):
def valid_string(cls, the_str): A class method that returns True or False depending on the validity of the passed string argument based on static constants which represent a valid name.
def valid_number(cls, the_val): A class method that returns True or False depending on the validity of the passed numeric argument based on static constants and the range that the romance/finance mutators should allow..
def valid_gender(gen): A static method that returns True or False depending on the validity of the gender character passed.
The Client Driver
In addition to main supply a global scope function of that compares and displays two DateProfile objects:
def display_two_profiles(profile1, profile2): This method will print the names of the two objects and show the fit value. It's output for a single call will look like this:
Fit between Sarah Somebody and Jane Peabody: 0.395.
Part 1
From your main program, you will instantiate a total of four DateProfile objects, applicant1, ... applicant4 manually from literal values in your program, i.e., do not involve the user with run-time input. Test the to_string() method by printing all objects using this method immediately after instantiation. Then for each of the four applicants, display the fits with the others - including themselves. Do this by calling display_two_profiles() for all possible combinations of the four applicants producing 16 comparison figures. (You will be comparing each applicant to him/herself in each of these four groups. This will serve to check whether the result is correct - it must be either a 1 or a 0 depending on the search_gender they requested, but never a number between (can you see why?)). It should also do some spot tests for mutators. Here is part of a sample output (with an optional mutator test at the end):
First without loops as four simple objects -------------- Date Profile: Sarah Somebody(F) searching for F, w/fin=5 and rom=9. Date Profile: Steve Nobody(M) searching for F, w/fin=2 and rom=10. Date Profile: Jane Peabody(F) searching for F, w/fin=9 and rom=2. Date Profile: Helen Anybody(F) searching for M, w/fin=3 and rom=7. Fit between Sarah Somebody and Sarah Somebody: 1.000. Fit between Sarah Somebody and Steve Nobody: 0.000. Fit between Sarah Somebody and Jane Peabody: 0.395. Fit between Sarah Somebody and Helen Anybody: 0.000. Fit between Steve Nobody and Sarah Somebody: 0.000. Fit between Steve Nobody and Steve Nobody: 0.000. Fit between Steve Nobody and Jane Peabody: 0.000. Fit between Steve Nobody and Helen Anybody: 0.780. Fit between Jane Peabody and Sarah Somebody: 0.395. Fit between Jane Peabody and Steve Nobody: 0.000. Fit between Jane Peabody and Jane Peabody: 1.000. Fit between Jane Peabody and Helen Anybody: 0.000. Fit between Helen Anybody and Sarah Somebody: 0.000. Fit between Helen Anybody and Steve Nobody: 0.780. Fit between Helen Anybody and Jane Peabody: 0.000. Fit between Helen Anybody and Helen Anybody: 0.000. Q rejected as gender f accepted as search gender ...
Part 2
Next, it should use lists and loops to do the same thing done in part 1, but with far fewer statements. The same four DateProfile objects should populate a list and you can take it from there. (You don't have to repleat the mutator tests.) Output of this part (same main, same run) would look something like:
... Now As a list of objects -------------- Date Profile: Sarah Somebody(F) searching for F, w/fin=5 and rom=9. Date Profile: Steve Nobody(M) searching for F, w/fin=2 and rom=10. Date Profile: Jane Peabody(F) searching for F, w/fin=9 and rom=2. Date Profile: Helen Anybody(F) searching for M, w/fin=3 and rom=7. Fit between Sarah Somebody and Sarah Somebody: 1.000. Fit between Sarah Somebody and Steve Nobody: 0.000. Fit between Sarah Somebody and Jane Peabody: 0.395. Fit between Sarah Somebody and Helen Anybody: 0.000. Fit between Steve Nobody and Sarah Somebody: 0.000. Fit between Steve Nobody and Steve Nobody: 0.000. Fit between Steve Nobody and Jane Peabody: 0.000. Fit between Steve Nobody and Helen Anybody: 0.780. Fit between Jane Peabody and Sarah Somebody: 0.395. Fit between Jane Peabody and Steve Nobody: 0.000. Fit between Jane Peabody and Jane Peabody: 1.000. Fit between Jane Peabody and Helen Anybody: 0.000. Fit between Helen Anybody and Sarah Somebody: 0.000. Fit between Helen Anybody and Steve Nobody: 0.780. Fit between Helen Anybody and Jane Peabody: 0.000. Fit between Helen Anybody and Helen Anybody: 0.000.
Once your assignment is graded and returned, you can view the instructor solution here:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started