Добрый день,
Валидатор ругается именно на вывод детей.
Посмотрите пожалуйста, в чем я ошибся?
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.List;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
ArrayList<Human> forChild = new ArrayList<>();
ArrayList<Human> forParents1 = new ArrayList<>();
ArrayList<Human> forParents2 = new ArrayList<>();
ArrayList<Human> forGrands = new ArrayList<>();
Human child1 = new Human("Child1", true, 14);
Human child2 = new Human("Child2", false, 12);
Human child3 = new Human("Chile3",true,10);
forChild.add(child1);
forChild.add(child2);
forChild.add(child3);
Human father = new Human("Папа", true, 55,forChild);
Human mother = new Human("Мама", false, 50,forChild);
forParents1.add(father);
forParents2.add(mother);
Human grandMohter1 = new Human("Бабушка1",false,75,forParents1);
Human grandMohter2 = new Human("Бабушка2", false, 73,forParents2);
Human grandFather1 = new Human("Дедушка1", true, 78,forParents1);
Human grandFather2 = new Human("Дедушка2", true,75,forParents2);
forGrands.add(grandMohter1);
forGrands.add(grandFather1);
forGrands.add(grandMohter2);
forGrands.add(grandFather2);
System.out.println(grandMohter1);
System.out.println(grandFather1);
System.out.println(grandMohter2);
System.out.println(grandFather2);
System.out.println(father);
System.out.println(mother);
System.out.println(child1);
System.out.println(child2);
System.out.println(child3);
}
public static class Human {
//напишите тут ваш код
String name;
boolean sex;
int age;
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;
}
}
}