Дичь какая то происходит... что не так делаю ?
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
Human child1 = new Human();
child1.name = "Федор";
child1.sex = true;
child1.age = 7;
Human child2 = new Human();
child2.name = "Клава";
child2.sex = false;
child2.age = 3;
Human child3 = new Human();
child3.name = "Lexa";
child3.sex = true;
child3.age = 3;
Human father = new Human();
father.name = "Емельян";
father.sex = true;
father.age = 30;
father.children.add(child1);
father.children.add(child2);
father.children.add(child3);
Human mother = new Human();
mother.name = "Зинка";
mother.sex = false;
mother.age = 27;
mother.children.add(child1);
mother.children.add(child2);
mother.children.add(child3);
Human grandfather1 = new Human();
grandfather1.name = "Борис";
grandfather1.sex = true;
grandfather1.age = 60;
grandfather1.children.add(mother);
Human grandfather2 = new Human();
grandfather2.name = "Федор";
grandfather2.sex = true;
grandfather2.age = 65;
grandfather2.children.add(father);
Human grandmother1 = new Human();
grandmother1.name = "Клава";
grandmother1.sex = false;
grandmother1.age = 60;
grandfather2.children.add(mother);
Human grandmother2 = new Human();
grandmother2.name = "Фрося";
grandmother2.sex = false;
grandmother2.age = 63;
grandfather2.children.add(father);
System.out.println(child1.toString());
System.out.println(child2.toString());
System.out.println(child3.toString());
System.out.println(grandmother1.toString());
System.out.println(grandmother2.toString());
System.out.println(grandfather1.toString());
System.out.println(grandfather2.toString());
System.out.println(mother.toString());
System.out.println(father.toString());
}
public static class Human {
String name;
boolean sex;
int age;
ArrayList <Human> children = new ArrayList<>();
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;
}
}
}