Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON Class DateProfile Create a class called DateProfile that has the followin

ID: 3895680 • Letter: P

Question

PYTHON

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 methodset-all( ), that takes all five parameters and acts like a mutator, except that it does not return a boolean. i.?., 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.

Explanation / Answer

MIN_ROMANCE_FINANCE = 0

MAX_ROMANCE_FINANCE = 1

MIN_NAME_LEN = 4

DEFAULT_GEND = 'M'

DEFAULT_SEARCH_GEND = 'F'

DEFAULT_NAME = 'Somebody'

def valid_string(cls, the_str):

return len(the_str) >= MIN_NAME_LEN

def valid_number(cls, the_val):

if the_val >= MIN_ROMANCE_FINANCE and the_val <= MAX_ROMANCE_FINANCE:

return True

return False

def valid_gender(gen):

if gen=='M' or gen =='F':

return True

return False

class DataProfile:

gender = ''

search_gender = ''

romance = 0

finance = 0

name = ''

def __init__(self, g=DEFAULT_GEND, sg=DEFAULT_SEARCH_GEND, r=0.3, f=0.5, n=DEFAULT_NAME):

self.set_gender(g)

self.set_search_gender(sg)

self.set_romance(r)

self.set_finance(f)

self.set_name(n)   

  

def get_gender(self):

return self.gender

def set_gender(self, g):

if valid_gender(g):

self.gender = g

return True

self.gender=DEFAULT_GEND

return False

def get_search_gender(self):

return self.search_gender

def set_search_gender(self,sg):

if valid_gender(sg):

self.search_gender = sg

return True

self.search_gender=DEFAULT_SEARCH_GEND

return False

def get_romance(self):

return self.romance

def set_romance(self,r):

if valid_number(self, r):

self.romance = r

return True

return False

def get_finance(self):

return self.finance

def set_finance(self,f):

if valid_number(self, f):

self.finance = f

return True

return False

def get_name(self):

return self.name

def set_name(self,n):

if valid_string(self, n):

self.name = n

return True

self.name=DEFAULT_NAME

return False

def fit_value(self, partner):

if self.determine_gender_fit(partner) == 0:

return 0

return (self.determine_romance_fit(partner) + self.determine_finance_fit(partner)) / 2

def determine_gender_fit(self, partner):

if self.search_gender == partner.get_gender():

return 1

return 0

def determine_romance_fit(self, partner):

if self.romance == partner.get_romance():

return 1.0

if abs(self.romance - partner.get_romance()) == 9:

return 0.1

return (self.romance - partner.get_romance()) / 2

  

def determine_finance_fit(self, partner):

if self.finance == partner.get_finance():

return 1.0

if abs(self.finance - partner.get_finance()) == 9:

return 0.1

return (self.finance - partner.get_finance()) / 2

def to_string(self):

print('Data Profile:')

print (' '+self.name + '(' + self.gender + ') searching for ' + self.search_gender + ', w/fin=' + str(self.finance) + ' and rom=' + str(self.romance) + '.')

def __str__(self):

self.to_string()

def display_two_profiles(profile1, profile2):

print('Fit between {} and {}: {}'.format(profile1.get_name(), profile2.get_name(), profile1.fit_value(profile2)))

application1 = DataProfile(n='Vishal')

application2 = DataProfile('F', 'M', 0.5, 0.7, 'Shivani')

application3 = DataProfile('M', 'M', 0.2, 0.8, 'Rajesh')

application4 = DataProfile('F', 'M', 0.9, 0.3, 'Rani')

application1.to_string()

application2.to_string()

application3.to_string()

application4.to_string()

display_two_profiles(application1, application1)

display_two_profiles(application1, application2)

display_two_profiles(application1, application3)

display_two_profiles(application1, application4)