Не понимаю, где упущение в коде.
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
ArrayList<Human> children = new ArrayList<>();
children.add(new Human("Lily", false, 13));
children.add(new Human("Anna", false, 12));
children.add(new Human("Sarah", false, 16));
ArrayList<Human> father = new ArrayList<>();
father.add(new Human("John", true, 54, children));
ArrayList<Human> mother = new ArrayList<>();
mother.add(new Human("Bella", false, 35, children));
ArrayList<Human> grandpa = new ArrayList<>();
grandpa.add(new Human("Patrick", true, 78, father));
grandpa.add(new Human("Tom", true, 89, mother));
ArrayList<Human> grandma = new ArrayList<>();
grandma.add(new Human("Zoe", false, 78, father));
grandma.add(new Human("Lara", false, 67, mother));
System.out.println(children.toString());
System.out.println(father.toString());
System.out.println(mother.toString());
System.out.println(grandpa.toString());
System.out.println(grandma.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;
System.out.println(this.toString());
}
public Human(String name, boolean sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
System.out.println(this.toString());
}
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;
}
}
}