Мб я не понял задачу, но сам ошибку не вижу, подскажите, плиз
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
ArrayList<Human> children = new ArrayList<>();
Human ch1 = new Human("Ребенок 1", true, 2);
Human ch2 = new Human("Ребенок 2", true, 22);
Human ch3 = new Human("Ребенок 3", true, 13);
children.add(ch1);
children.add(ch2);
children.add(ch3);
ArrayList<Human> mothers = new ArrayList<>();
ArrayList<Human> fathers = new ArrayList<>();
Human father = new Human("Папа", true, 43, children);
Human mother = new Human("Мама", false, 33, children);
fathers.add(father);
mothers.add(mother);
Human gFather1 = new Human("Папа Мамы", true, 76, mothers);
Human gMother1 = new Human("Мама Мамы", false, 77, mothers);
Human gFather2 = new Human("Папа Папы", true, 67, fathers);
Human gMother2 = new Human("Мамы Папы", false, 76, fathers);
ArrayList<Human> family = new ArrayList<>();
family.add(ch1);
family.add(ch2);
family.add(ch3);
family.add(father);
family.add(mother);
family.add(gFather1);
family.add(gMother1);
family.add(gFather2);
family.add(gMother2);
System.out.println(family);
}
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++) {
Human child = this.children.get(i);
text += ", " + child.name;
}
}
return text;
}
}
}