сделал уже "в лоб" совсем. Валидацию не проходит с формулировкой "Программа должна создавать объекты и заполнять их так, чтобы получилось: два дедушки, две бабушки, отец, мать, трое детей."
При этом компилируется все ок, выводит все ок
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
import java.util.ArrayList;
import java.util.Collections;
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
ArrayList<Human> MamaPapa = new ArrayList<>();
ArrayList<Human> Dedbabka = new ArrayList<>();
Human ded1 = new Human("Ded1", true, 71, Dedbabka);
Human ded2 = new Human("Ded2", true, 72, Dedbabka);
Human babka1 = new Human("babka1", false, 70, Dedbabka);
Human babka2 = new Human("babka2", false, 69, Dedbabka);
Human Father = new Human("Father", true, 45, MamaPapa);
Human Mother = new Human("Mother", false, 46, MamaPapa);
Human child1 = new Human("child1", false, 10, new ArrayList<>());
Human child2 = new Human("child2", true, 11, new ArrayList<>());
Human child3 = new Human("child3", false, 12, new ArrayList<>());
MamaPapa.add(child1);
MamaPapa.add(child2);
MamaPapa.add(child3);
Dedbabka.add(Father);
Dedbabka.add(Mother);
System.out.println(ded1);
System.out.println(ded2);
System.out.println(babka1);
System.out.println(babka2);
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;
Integer age;
ArrayList<Human> children;
public Human (String name, Boolean sex, Integer 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;
if (this.children != null) {
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;
}
}
}