Не проходит валидацию последнего пункта, может я что-то делаю не так (или не понял что от меня хотят)
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
ArrayList<Human> children = new ArrayList<>();
Human son = new Human("son", true, 10);
children.add(son);
Human son1 = new Human("son2", true, 10);
children.add(son1);
Human daughter = new Human("daughter", false, 10);
children.add(daughter);
Human ded1 = new Human("Ded1", true, 76);
Human ded2 = new Human("Ded2", true, 76);
Human baba1 = new Human("Baba1", false, 76);
Human baba2 = new Human("Baba2", false, 76);
Human father = new Human("father", true, 36);
Human mother = new Human("mother", false, 36);
father.children.addAll(children);
mother.children.addAll(children);
ded1.children.add(father);
baba1.children.add(father);
ded2.children.add(mother);
baba2.children.add(mother);
System.out.println(ded1.toString());
System.out.println(ded2.toString());
System.out.println(baba1.toString());
System.out.println(baba2.toString());
System.out.println(father.toString());
System.out.println(mother.toString());
System.out.println(ded1.children.toString());
System.out.println(baba1.children.toString());
System.out.println(ded2.children.toString());
System.out.println(baba2.children.toString());
System.out.println(father.children.toString());
System.out.println(mother.children.toString());
}
public static class Human {
//напишите тут ваш код
String name;
boolean sex;
int age;
ArrayList<Human> children = new ArrayList<Human>();
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;
}
}
}