Вроде-бы все логично. Два деда, две бабушки, их дети и внук. Но валидатор не устраивает данный факт. Нервы сдали решил обратиться к общественности.
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
Human babyBoy = new Human("Jake", true, 7);
Human dad = new Human("Tom", true, 43, babyBoy);
Human mom = new Human("Lusy", false, 38);
Human grandPa1 = new Human("Fill", true, 72, dad);
Human grandMa1 = new Human("Boi", false, 70);
Human grandPa2 = new Human("F", true, 80, mom);
Human grandMa2 = new Human("B", false, 34);
System.out.println(babyBoy.toString());
System.out.println(dad.toString());
System.out.println(mom.toString());
System.out.println(grandPa1.toString());
System.out.println(grandMa1.toString());
System.out.println(grandPa2.toString());
System.out.println(grandMa2.toString());
}
public static class Human {
//напишите тут ваш код
String name;
boolean sex;
int age;
ArrayList<Human> children = new ArrayList<>();
public Human(String name, boolean sex, int age, Human ... humans) {
this.name = name;
this.sex = sex;
this.age = age;
Collections.addAll(this.children, humans);
}
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;
}
}
}