Вроде бы все поля соответствуют, может что не вижу?
package com.javarush.task.task08.task0824;
import java.util.*;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
Human child1 = new Human("child1", false, 18, null, null, null);
Human child2 = new Human("chil2", false, 20, null, null, null);
Human child3 = new Human("child3", true, 19, null, null, null);
Human father = new Human("father", true, 40, child1, child2, child3);
Human mother = new Human("mother", true, 38, child1, child2, child3);
Human grandfather1 = new Human("Ded1", true, 80, mother, null, null);
Human grandfather2 = new Human("Ded2", true, 78, father, null, null);
Human grandMother1 = new Human("Baba1", false, 82, father, null, null);
Human grandMother2 = new Human("Baba2", false, 82, mother, null, null);
System.out.println(child1);
System.out.println(child2);
System.out.println(child3);
System.out.println(father);
System.out.println(mother);
System.out.println(grandfather1);
System.out.println(grandfather2);
System.out.println(grandMother1);
System.out.println(grandMother2);
}
public static class Human {
private String name;
private boolean sex;
private int age;
private ArrayList<Human> children;
public Human(String name, boolean sex, int age,
Human children1, Human children2, Human children3) {
this.name = name;
this.sex = sex;
this.age = age;
children = new ArrayList<>();
if (children1 != null) {
this.children.add(children1);
}
if (children2 != null) {
this.children.add(children2);
}
if (children3 != null) {
this.children.add(children3);
}
}
public String toString() {
String text = "";
text += "Имя: " + this.name;
text += ", пол: " + (this.sex ? "мужской" : "женский");
text += ", возраст: " + this.age;
int childCount = this.children.size();
if (childCount > 0) {
text += ", дети: " + this.children.get(0).name;
for (int i = 1; i < childCount; i++) {
Human child = this.children.get(i);
text += ", " + child.name;
}
}
return text;
}
}
}