Мне кажется, где-то тут ошибка в добавлении дедушек и бабушек. Не пойму что-то
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.*;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
Human child1 = new Human ("Olga", false, 15);
Human child2 = new Human ("Stanislav", true, 13);
Human child3 = new Human ("Marina", false, 17);
Human mother = new Human("Svetlana", false, 50, new ArrayList<>(Arrays.asList(child1, child2, child3)));
Human father = new Human("Ilya", true, 50, new ArrayList<>(Arrays.asList(child1, child2, child3)));
Human grandma1 = new Human("Olga", false, 70, new ArrayList<>(Arrays.asList(mother)));
Human grandpa1 = new Human("Alex", true, 78, new ArrayList<>(Arrays.asList(father)));
Human grandma2 = new Human("Marina", false, 70, new ArrayList<>(Arrays.asList(mother)));
Human grandpa2 = new Human("Peter", true, 78, new ArrayList<>(Arrays.asList(father)));
System.out.println (child1 + " " + child2 + " " +
child3 + " " + mother + " " + father + " " + grandma1 + " " + grandpa1 + " " + grandma2 + " " + grandpa2);
}
public static class Human {
String name;
boolean sex;
int age;
ArrayList<Human> children = new ArrayList<Human>();
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;
ArrayList<String> list = new ArrayList<>();
}
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;
}
}
}