помогите, пожалуйста)
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
import java.util.ArrayList;
import java.util.Collections;
public class Solution {
static ArrayList<Human> humans = new ArrayList<Human>();
public static void main(String[] args) {
Human sin1 = new Human("sin1",true,14);
Human sin2 = new Human("sin2",true,14);
Human sin3 = new Human("sin3",true,14);
Human mat = new Human("mat",false,32,sin1,sin2,sin3);
Human otec = new Human("otec",true,34,sin1,sin2,sin3);
Human ded1 = new Human("dedmama",true,54,mat);
Human ded2 = new Human("dedpapa",true,54,otec);
Human baba1 = new Human("babamama",true,54,mat);
Human baba2 = new Human("babapapa",true,54,otec);
for (Human result:humans
) {
System.out.println(result.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, Human...human) {
this.name = name;
this.sex = sex;
this.age = age;
Collections.addAll(this.children,human);
humans.add(Human.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;
}
}
}