Кто подскажет где ошибка в коде?
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) {
ArrayList<Human> noKids = new ArrayList<>();
Human four = new Human("sun1",true,20,null);
Human four1 = new Human("sun2",true,15,null);
Human four2 = new Human("sun3",true,10,null);
ArrayList<Human> childrens = new ArrayList<>();
childrens.add(four);
childrens.add(four1);
childrens.add(four2);
Human three = new Human("otec1",true,40,childrens);
ArrayList<Human> dad = new ArrayList<>();
dad.add(three);
Human three1 = new Human("mama1",false,35,childrens);
ArrayList<Human> mam = new ArrayList<>();
mam.add(three1);
Human one1 = new Human("ded2",true,70,dad);
Human two1 = new Human("baba2",false,66,dad);
Human one = new Human("ded1", true,65,mam);
Human two = new Human("baba1",false,61,mam);
//напишите тут ваш код
System.out.println(one.toString());
System.out.println(one1.toString());
System.out.println(two.toString());
System.out.println(two1.toString());
System.out.println(three.toString());
System.out.println(three1.toString());
System.out.println(four.toString());
System.out.println(four1.toString());
System.out.println(four2.toString());
}
public static class Human {
String name;
Boolean sex;
int age;
ArrayList<Human> children;
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;
}
}
}