Всем доброго времени суток, прошу помощи. сможет ли кто то мне объяснить что я делаю не так?
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("Ben", 21 , true));
children.add(new Human("Siu", 18, false));
children.add(new Human ("Robert", 13,true));
Human grandpaFirst = new Human("GrandPa", 90, true);
Human grandpaSecond = new Human("Stiven", 90,true);
Human grandmaFirst = new Human("GrandMa", 88,false);
Human grandmaSecond = new Human("Betty", 80, false);
Human father = new Human("Father", 50,false, children);
Human mother = new Human("Mam", 42,false, children);
System.out.println(grandmaFirst.toString());
System.out.println(grandmaSecond.toString());
System.out.println(grandpaFirst.toString());
System.out.println(grandpaSecond.toString());
System.out.println(father.toString());
System.out.println(mother.toString());
}
public static class Human {
String name;
boolean sex;
int age;
ArrayList<Human> children;
public Human(String name, int age, boolean sex, ArrayList<Human> children){
this.name = name;
this.age = age;
this.sex = sex;
this.children = children;
}
public Human(String name, int age, boolean sex){
this.name = name;
this.age = age;
this.sex = sex;
}
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;
}
}
}