не выводит список с детьми, почему?
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
ArrayList<Human> children = new ArrayList<>();
children.add(new Human("Дочь", false, 20));
children.add(new Human("Сын", true, 22));
children.add(new Human("Собака", true, 4));
ArrayList<Human> parents = new ArrayList<>();
parents.add(new Human("Мама", false, 48, children));
parents.add(new Human("Папа", true, 50, children));
ArrayList<Human> grandParents= new ArrayList<>();
grandParents.add(new Human("Дедушка", true, 80, parents));
grandParents.add(new Human("Бабушка", false, 75, parents));
grandParents.add(new Human("Дедушка2", true, 88, parents));
grandParents.add(new Human("Бабушка2", false, 82, parents));
for (int i = 0; i< grandParents.size(); i++)
System.out.println(grandParents.get(i));
for (int i = 0; i< parents.size(); i++)
System.out.println(parents.get(i));
for (int i = 0; i< children.size(); i++)
System.out.println(children.get(i));
}
public static class Human {
public String name;
public boolean sex;
public int age;
public ArrayList<Human> children;
//напишите тут ваш код
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;
}
}
}