I should write a method that returns all cousins of the Person as an array of Person objects. A Person object has mother, father, children[] etc. as its instance variables and I should use this method to find all siblings of a Person's uncles and aunts then their children.
public Person[] allSiblings(){
int a = this.mother.children.length - 1;
Person[] siblings = new Person[a];
for(i=0; i<siblings.length; i++){
if(this.mother.children[i] == this)
continue;
else{
siblings[i] = this.mother.children[i];
}
}
return siblings;
}
So how can I merge these children arrays and return as one Person array in allCousins()
method. I know it would be easier to use ArrayList but we are not allowed.
Thanks in advance.