Вроде всё работает и выводит на экран согласно условиям но валидатор не пропускает ! Как я только не шаманил и сколько я раз не переписывал ..... результат один - последний пункт не проходит !
package com.javarush.task.task08.task0824;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
Human childBoy = new Human("Son", true, 10);
Human childDoch = new Human("Doch", false, 16);
Human childDoch2 = new Human("Doch", false, 16);
ArrayList <Human>kinders = new ArrayList<>(Arrays.asList(childBoy, childDoch,childDoch2));
Human father = new Human("father", true, 37, childBoy, childDoch,childDoch2);
Human mother = new Human("Mother", false,45, childBoy, childDoch);
ArrayList <Human> parents = new ArrayList<>(Arrays.asList(father, mother));
Human grandFather = new Human("Дед", true, 65, father, mother);
Human grandFather1 = new Human("Дед", true, 65, father, mother);
Human grandMother = new Human("Baba1", false, 55, father, mother);
Human grandMother1 = new Human("Baba2", false, 57, father, mother);
ArrayList <Human> oldmen = new ArrayList<>(Arrays.asList(grandFather, grandFather1, grandMother, grandMother1));
ArrayList <Human> family = new ArrayList<>();
family.addAll(kinders);
family.addAll(parents);
family.addAll(oldmen);
for (Human x : family)
{
System.out.println(x.toString());
}
}
public static class Human {
String name;
boolean sex;
int age;
ArrayList<Human>children = new ArrayList<>();
Human (String name, boolean sex, int age, Human ... x)
{
this.name = name;
this.sex = sex;
this.age = age;
Collections.addAll(this.children,x);
}
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;
}
}
}