Create a class called DateProfile that has the following private instance member
ID: 3845308 • Letter: C
Question
Create a class called DateProfile that has the following private instance members:
gender - a char, the gender of the applicant ('M' or 'F').
searchGender - a char, 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 public 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 default constructor is called or if a parameter-taking constructor is called 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 member functions of class DateProfile (at a minimum):
Accessors and Mutators for each field (instance member). For example: char getGender() and bool setGender(char gdr). In addition to individual mutators, create a public void setAll( ... ) that takes all five parameters and acts like a mutator, except that it has a void return type, 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 a public void setDefaults() that sets all five members to their default values.
Constructors that take no parameters (default) and all 5 parameters. To avoid code duplication make sure these constructors utilize the above mutators rather than do anything direct assignments or testing.
double fitValue(DateProfile partner), which returns a number from 0.0 (very bad fit) to 1.0 (perfect fit). The public instance method compares the calling object (this) to the object passed as a parameter. This method should call three private methods determineGenderFit( ... ), determineRomanceFit( ... ) and determineFinanceFit( ... ), 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 (regardless of the other values) and return the average of finance and romance values if gender is compatible.
double determineGenderFit(DateProfile partner) This private 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 fitValue(), not directly by the client main().
double determineRomanceFit(DateProfile partner) This private instance method returns a number from 0.0 to 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 fitValue(), not directly by the client main().
double determineFinanceFit(DateProfile partner) This private instance method returns a number from 0.0 to 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 fitValue(), not directly by the client main().
The Client Driver
In addition to main() supply a global scope method of that compares and displays two DateProfile objects:
void displayTwoProfiles(DateProfile profile1, DateProfile 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 Joe Somebody and Jane Peabody:
0.888889
From your main(), 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. Then for each of the four applicants, display the fits with the others - including themselves. Do this by calling displayTwoProfiles() 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 searchGender they requested, but never a number between).
Explanation / Answer
Here is the code and output for the question. Please don't forget to rate the answer if it helped. Thank you very much.
DateProfile.java
public class DateProfile {
//public constants
public static final int MIN_ROMANCE = 1;
public static final int MAX_ROMANCE = 10;
public static final int MIN_FINANCE = 1;
public static final int MAX_FINANCE = 10;
//default values
private static final char DEFAULT_GEN = 'M';
private static final char DEFAULT_SEARCH_GEND = 'F';
private static final String DEFAULT_NAME= "No Name";
private static final int DEFAULT_ROMANCE= 5;
private static final int DEFAULT_FINANCE= 5;
//private instance variables
private char gender;
private char searchGender;
private int romance;
private int finance;
private String name;
//constructors
public DateProfile()
{
setDefaults();
}
public DateProfile(char gndr, char searchGndr, int rom, int fin, String name)
{
setAll(gndr, searchGndr, rom, fin, name);
}
//accessors and mutators
public char getGender() {
return gender;
}
public void setGender(char gender) {
if(gender == 'M' || gender =='F')
this.gender = gender;
else
this.gender = DEFAULT_GEN;
}
public char getSearchGender() {
return searchGender;
}
public void setSearchGender(char searchGender) {
if(searchGender == 'M' || searchGender =='F')
this.searchGender = searchGender;
else
this.searchGender = DEFAULT_SEARCH_GEND;
}
public int getRomance() {
return romance;
}
public void setRomance(int romance) {
if(romance >= MIN_ROMANCE && romance <= MAX_ROMANCE)
this.romance = romance;
else
this.romance = DEFAULT_ROMANCE;
}
public int getFinance() {
return finance;
}
public void setFinance(int finance) {
if(finance >= MIN_FINANCE & finance <=MAX_FINANCE)
this.finance = finance;
else
this.finance = DEFAULT_FINANCE;
}
public String getName() {
return name;
}
public void setName(String name) {
if(name != null )
this.name = name;
else
this.name = DEFAULT_NAME;
}
void setAll(char gndr, char searchGndr,int rom, int fin, String name)
{
setGender(gndr);
setSearchGender(searchGndr);
setRomance(rom);
setFinance(fin);
setName(name);
}
void setDefaults()
{
setGender(DEFAULT_GEN);
setSearchGender(DEFAULT_SEARCH_GEND);
setRomance(DEFAULT_ROMANCE);
setFinance(DEFAULT_FINANCE);
setName(DEFAULT_NAME);
}
public double fitValue(DateProfile partner)
{
if(determineGenderFit(partner) == 0)
return 0;
else
{
double total = determineFinanceFit(partner)+determineRomanceFit(partner);
return total / 2;//return average of finance and romance fit values
}
}
private double determineGenderFit(DateProfile partner)
{
if(getSearchGender() == partner.getGender())
return 1;
else
return 0;
}
private double determineRomanceFit(DateProfile partner)
{
int diff = Math.abs(getRomance() - partner.getRomance());
if(diff == 0)
return 1;
else
{
int max_romance_diff = MAX_ROMANCE - MIN_ROMANCE;
double fit = ((double)( max_romance_diff - diff ))/max_romance_diff;
if(fit == 0)
fit = 0.1;
return fit;
}
}
private double determineFinanceFit(DateProfile partner)
{
int diff = Math.abs(getFinance() - partner.getFinance());
if(diff == 0)
return 1;
else
{
int max_finance_diff = MAX_FINANCE - MIN_FINANCE;
double fit = ((double)( max_finance_diff - diff ))/max_finance_diff;
if(fit == 0)
fit = 0.1;
return fit;
}
}
}
DateProfileDriver.java
public class DateProfileDriver {
static void displayTwoProfiles(DateProfile profile1, DateProfile profile2)
{
System.out.println("Fit between "+profile1.getName() + " and "+profile2.getName()+": "+profile1.fitValue(profile2));
}
public static void main(String[] args) {
DateProfile app1 = new DateProfile('M','F',9,9,"Joe");
DateProfile app2 = new DateProfile('F','M',8,5,"Jane");
DateProfile app3 = new DateProfile('M','F',9,3,"Bob");
DateProfile app4 = new DateProfile('F','M',9,9,"Alice");
displayTwoProfiles(app1, app1);
displayTwoProfiles(app1, app2);
displayTwoProfiles(app1, app3);
displayTwoProfiles(app1, app4);
displayTwoProfiles(app2, app1);
displayTwoProfiles(app2, app2);
displayTwoProfiles(app2, app3);
displayTwoProfiles(app2, app4);
displayTwoProfiles(app3, app1);
displayTwoProfiles(app3, app2);
displayTwoProfiles(app3, app3);
displayTwoProfiles(app3, app4);
displayTwoProfiles(app4, app1);
displayTwoProfiles(app4, app2);
displayTwoProfiles(app4, app3);
displayTwoProfiles(app4, app4);
}
}
output
Fit between Joe and Joe: 0.0
Fit between Joe and Jane: 0.7222222222222222
Fit between Joe and Bob: 0.0
Fit between Joe and Alice: 1.0
Fit between Jane and Joe: 0.7222222222222222
Fit between Jane and Jane: 0.0
Fit between Jane and Bob: 0.8333333333333333
Fit between Jane and Alice: 0.0
Fit between Bob and Joe: 0.0
Fit between Bob and Jane: 0.8333333333333333
Fit between Bob and Bob: 0.0
Fit between Bob and Alice: 0.6666666666666666
Fit between Alice and Joe: 1.0
Fit between Alice and Jane: 0.0
Fit between Alice and Bob: 0.6666666666666666
Fit between Alice and Alice: 0.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.