Hi again, I have a class that is supposed to match different people of different genders together under different rules. For example, they are supposed to live in the same postal district. The problem is Java seems to be mismatching people, and I think its because it isn't comparing the strings correctly. Can you see anything wrong with the following class? Thanks.
public class Person{
String n;
double a;
double h;
String p;
String s;
String d;
String g;
public Person (String gender,String name,String pattern, String smoke, String district,double age,double height){
g=gender;
n=name;
a=age;
h=height;
p=pattern;
s=smoke;
d=district;
}
public String getG() {
return this.g;
}
public String getN(){
return this.n;
}
public double getA(){
return this.a;
}
public double getH(){
return this.h;
}
public String getP(){
return this.p;
}
public String getS(){
return this.s;
}
public String getD(){
return this.d;
}
public boolean checkMatch(Person other){
if (this.getA()<26&&this.getG().equals("male")&&other.getA()-this.getA()>1||
(this.getA()<26&&other.getG().equals("male")&&other.getA()-this.getA()>1)||
(!((this.getH()-other.getH()<25)))
||(!((other.getH()-this.getH())<25))){
return false;
}
else if (this.getG().equals(other.getG())){
return false;
}
else if (!(this.getS().equals(other.getS()))){
return false;
}else if(this.getP().equals(other.getP())&&this.getD().equals(other.getD())){
return true;
}else{
return false;
}
}
public String findMatch(Person other,Person other2, Person other3,Person other4,Person other5){
String part1="";
String part2="";
String part3="";
String part4="";
String part5="";
if (this.checkMatch(other)==true){
part1= other.getN();
}else if(this.checkMatch(other2)==true){
part2= other2.getN();
}else if(this.checkMatch(other3)==true){
part3= other3.getN();
}else if(this.checkMatch(other4)==true){
part4= other3.getN();
}else if(this.checkMatch(other5)==true){
part5= other3.getN();
}
return (part1+" "+part2+" "+part3+" "+part4+" "+part5);
}
}