Не пойму в чем причина, все проверено и выводится.
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.List;
/*
Собираем семейство
*/
public class Solution {
public static ArrayList<Human> allHum = new ArrayList<>();
public static void main(String[] args) {
//напишите тут ваш код
Human children1 = new Human();
children1.name = "Boy1";
children1.age = 15;
children1.sex = true;
Human children2 = new Human();
children2.name = "Boy2";
children2.age = 17;
children2.sex = true;
Human children3 = new Human();
children3.name = "Girl1";
children3.age = 15;
children3.sex = false;
Human father = new Human();
father.name = "DADDY";
father.age = 40;
father.sex = true;
father.children.add(children1);
father.children.add(children2);
father.children.add(children3);
Human mother = new Human();
mother.name = "MAM";
mother.age = 39;
mother.sex = false;
mother.children.add(children1);
mother.children.add(children2);
mother.children.add(children3);
Human grandFather = new Human();
grandFather.name = "DED1";
grandFather.age = 65;
grandFather.sex = true;
grandFather.children.add(mother);
Human grandMother = new Human();
grandMother.name = "BAB1";
grandMother.age = 64;
grandMother.sex = false;
grandMother.children.add(mother);
Human grandFather2 = new Human();
grandFather2.name = "DED2";
grandFather2.age = 72;
grandFather2.sex = true;
grandFather2.children.add(father);
Human grandMother2 = new Human();
grandMother2.name = "BAB2";
grandMother2.age = 80;
grandMother2.sex = false;
grandMother2.children.add(father);
for (Human hum : allHum){
System.out.println(hum);
}
}
public static class Human {
//напишите тут ваш код
public String name;
public boolean sex;
public int age;
ArrayList <Human> children;
public Human(){
children = new ArrayList<Human>();
Solution.allHum.add(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;
}
}
}