Подскажите, для чего в классе Human создается список children, если он итак создается в методе main()?
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
ArrayList<Human> children = new ArrayList<>();
children.add(new Human("child1", true, 10));
children.add(new Human("child2", true, 12));
children.add(new Human("child3", false, 15));
ArrayList<Human> parent1 = new ArrayList<>();
ArrayList<Human> parent2 = new ArrayList<>();
parent1.add(new Human("father", true, 40, children));
parent2.add(new Human("mother", false, 35, children));
ArrayList<Human> grandparents = new ArrayList<>();
grandparents.add(new Human("grandfather1", true, 90, parent1));
grandparents.add(new Human("grandfather2", true, 80, parent2));
grandparents.add(new Human("grandmother1", false, 85, parent1));
grandparents.add(new Human("grandmother2", false, 75, parent2));
for(Human human : grandparents){
System.out.println(human);
}
for(Human human : parent1){
System.out.println(human);
}
for(Human human : parent2){
System.out.println(human);
}
for(Human human : children){
System.out.println(human);
}
}
public static class Human {
private String name;
private boolean sex;
private 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, ArrayList<Human> children){
this.name = name;
this.sex = sex;
this.age = age;
this.children = children;
}
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;
}
}
}