вывод верный, но валидатор не пропускает
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
import java.util.*;
public class Solution {
static ArrayList<Human> allHuman = new ArrayList<Human>();
public static void main(String[] args) throws Exception {
//напишите тут ваш код
Human grandFather1 = new Human("Zhenya", true, 80);
Human grandFather2 = new Human("Vasea", true, 88);
Human grandMother1 = new Human("Maria", false, 80);
Human grandMother2 = new Human("Katea", false, 99);
Human father = new Human("Vova", true, 45, grandFather1, grandMother1);
Human mother = new Human("Dawa", false, 42, grandFather2, grandMother2);
Human children1 = new Human("Egor", true, 18, father, mother);
Human children2 = new Human("Sasha", true, 25, father, mother);
Human children3 = new Human("Lena", false, 21, father, mother);
for(Human human : Solution.allHuman){
System.out.println(human);
}
}
public static class Human {
//напишите тут ваш код
String name;
boolean sex;
int age;
ArrayList<Human> children = new ArrayList<Human>();
public Human (String name, boolean sex, int age) {
Solution.allHuman.add(this);
this.name = name;
this.sex = sex;
this.age = age;
}
public Human (String name, boolean sex, int age, Human father, Human mother) {
Solution.allHuman.add(this);
this.name = name;
this.sex = sex;
this.age = age;
father.children.add(this);
mother.children.add(this);
}
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;
}
}
}