не проходит последний пункт
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
Human son1 = new Human("Олег", true, 21);
Human son2 = new Human("Антон", true, 19);
Human doch = new Human("Лиза", false, 17);
ArrayList<Human> child1 = new ArrayList<Human>();
child1.add(son1);
child1.add(son2);
child1.add(doch);
Human papa = new Human("Алексей", true, 50,child1);
Human mama = new Human("Антонина", false, 45,child1);
ArrayList<Human> child2 = new ArrayList<Human>();
child2.add(papa);
ArrayList<Human> child3 = new ArrayList<Human>();
child3.add(mama);
Human opa1 = new Human("Евлампий", true, 76, child2);
Human oma1 = new Human("Агафья", false, 74,child2);
Human opa2 = new Human("Евстафий", true, 73,child3);
Human oma2 = new Human("Мойра", false, 70,child3);
System.out.println(child1.toString());
System.out.println(child2.toString());
System.out.println(child3.toString());
}
public static class Human {
String name;
boolean sex;
int age;
ArrayList<Human> children = new ArrayList<>();
public Human(String name, boolean sex, int age){
this.name = name;
this.sex = sex;
this.age = age;
}
public Human(String name, boolean sex, int age, ArrayList<Human> children){
this.name = name;
this.sex = sex;
this.age = age;
this.children = children;
}
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;
}
}
}