Я что-то не так сделал или нужно менять исходный код?
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
Human kid1 = new Human("Ребенок1", true, 6, null);
Human kid2 = new Human("Ребенок2", true, 5, null);
Human kid3 = new Human("Ребенок3", false, 4, null);
ArrayList<Human>secondg = new ArrayList<>();
secondg.add(kid1);
secondg.add(kid2);
secondg.add(kid3);
Human father = new Human("Отец", true, 29, secondg);
Human mother = new Human("Мать", false, 31, secondg);
ArrayList<Human> firstgf = new ArrayList<>();
firstgf.add(father);
ArrayList<Human> firstgm = new ArrayList<>();
firstgm.add(mother);
Human grandmom1 = new Human("Бабушка1", false, 66, firstgf);
Human grandmom2 = new Human("Бабушка2", false, 69, firstgm);
Human grandpop1 = new Human("Дедушка1", true, 71, firstgf);
Human grandpop2 = new Human("Дедушка2", true, 71, firstgm);
System.out.println(grandpop1.toString());
System.out.println(grandpop2.toString());
System.out.println(grandmom1.toString());
System.out.println(grandmom2.toString());
System.out.println(father.toString());
System.out.println(mother.toString());
System.out.println(kid1.toString());
System.out.println(kid2.toString());
System.out.println(kid3.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> kids) {
this.name = name;
this.sex = sex;
this.age = age;
this.children.addAll(kids);
}
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;
}
}
}