помогите решить, пожалуйста
package com.javarush.task.task08.task0824;
import java.util.*;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
ArrayList<Human> children = new ArrayList<>();
ArrayList<Human> per1 = new ArrayList<>();
ArrayList<Human> per2 = new ArrayList<>();
ArrayList<Human> grand = new ArrayList<>();
children.add(new Human("Джон", true, 4));
children.add(new Human("Лея", false, 6));
children.add(new Human("Дана", false, 10));
per1.add( new Human("Боб", true, 41, children));
per2.add( new Human("Элиза", false, 39, children));
grand.add( new Human("Мартин", true, 70, per1));
grand.add( new Human("Роб", true, 71, per2));
grand.add( new Human("Лилия", false, 69, per1));
grand.add( new Human("Лидия", false, 68, per2));
for(Human x:grand){
System.out.println(x.toString());}
for(Human x:per1){
System.out.println(x.toString());}
for(Human x:per2){
System.out.println(x.toString());}
for(Human x:children){
System.out.println(x.toString());}
//напишите тут ваш код
}
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;
}
}