Это валидатор козлится? или я что то делаю не то? вроде все условия выполнены
package com.javarush.task.task08.task0824;
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
ArrayList<Human> kids = new ArrayList<>();
kids.add(new Human("Vasya",true,14));
kids.add(new Human("Petya",true,11));
kids.add(new Human("Anton",true,12));
ArrayList<Human> fathers = new ArrayList<>();
fathers.add(new Human("batia",true,25,kids));
fathers.add(new Human("mamka",false,33,kids));
ArrayList<Human> grandfathers = new ArrayList<>();
grandfathers.add(new Human("ded",true,66,fathers));
grandfathers.add(new Human("ded2",true,65,fathers));
grandfathers.add(new Human("babka",false,77,fathers));
grandfathers.add(new Human("babka2",false,76,fathers));
for (Human human : kids){
System.out.println(human);
}
for (Human human : fathers){
System.out.println(human);
}
for(Human human : grandfathers){
System.out.println(human);
}
}
public static class Human {
String name;
boolean sex;
int age;
ArrayList<Human> children = new ArrayList<>();
public Human (String name, boolean sex, int age, ArrayList<Human> children){
this.name = name;
this.sex = sex;
this.age = age;
this.children = children;
}
public Human (String name, boolean sex, int age){
this.name = name;
this.sex = sex;
this.age = age;
}
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++) {
if(this.children == null){
return text;
}
Human child = this.children.get(i);
text += ", " + child.name;
}
}
return text;
}
}
}