не понимаю(
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.List;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
Human children1 = new Human("vasya",true,15);
Human children2 = new Human("Karina",false,22);
Human children3 = new Human("Ivan",true,20);
ArrayList<Human> children = new ArrayList<>();
children.add(children1);
children.add(children2);
children.add(children3);
ArrayList<Human> father = new ArrayList<>();
Human dad = new Human("Ivan",true, 35,children );
father.add(dad);
Human mother = new Human("Katya",false, 30, children);
ArrayList<Human> mom = new ArrayList<>();
mom.add(mother);
Human granfather1 = new Human ("Petro", true,77,father);
Human grandmother1 = new Human ("Elena", false,60,father);
Human grandfather2 = new Human ("Vasliy",true,80,mom);
Human grandmother2 = new Human ("tatyana",false,65,mom);
System.out.println(dad.toString());
System.out.println(mother.toString());
System.out.println(children1.toString());
System.out.println(children2.toString());
System.out.println(children3.toString());
System.out.println(grandfather2.toString());
System.out.println(grandmother2.toString());
System.out.println(grandmother1.toString());
System.out.println(granfather1.toString());
}
public static class Human {
private static String name;
private static boolean sex;
private static int age;
ArrayList<Human> children = new ArrayList<>();
public Human (String name, boolean sex, int age)
{
this.name=name;
this.sex=sex;
this.age=age;
}
public Human(String name, boolean sex, int age, Human children)
{
this.name = name;
this.sex=sex;
this.age=age;
this.children = new ArrayList<Human>();
}
//напишите тут ваш код
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;
}
}
}