программа работает, все правильно выводит, но не проходит по последнему условию
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
import java.util.*;
import java.io.*;
import java.*;
public class Solution {
public static void main(String[] args) {
ArrayList<Human> children = new ArrayList<>();
ArrayList<Human> out = new ArrayList<>();
Human chil = new Human ("chil111", true, 19);
Human boy = new Human("boy111", true, 18);
Human girl = new Human("girl111", false, 17);
Human dad = new Human ("dad111", true, 45, chil, boy, girl);
Human mom = new Human("mom111", false, 45, chil, boy, girl);
Human ded = new Human("ded111", true, 98, dad);
Human ded2 = new Human("ded2111", true, 96, mom);
Human bab = new Human ("bab111", false, 87, dad);
Human bab2 = new Human ("bab2111", false, 78, mom);
out.add(ded); out.add(ded2); out.add(bab); out.add(bab2);
out.add(dad); out.add(mom);
out.add(chil); out.add(boy); out.add(girl);
System.out.println(out);
}
public static class Human {
String name;
boolean sex;
int age;
ArrayList<Human> children = new ArrayList<>();
public Human(String name, boolean sex, int age, Human ... human){
this.name = name;
this.sex = sex;
this.age = age;
Collections.addAll(this.children, human);//напишите тут ваш код
}
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;
}
}
}