Когда хочу занести детей в список, то есть на 48 строчке кода, выбивает ошибку
Короче в итоге, ошибка в 48 строке и в 80 строке кода
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> motherList = new ArrayList<>();
ArrayList<Human> fatherList = new ArrayList<>();
ArrayList<Human> childrenList = new ArrayList<>();
Human firstGrandfather = new Human("дедушка Вова", true, 67, motherList);
Human secondGrandfather = new Human("дедушка Коля", true, 62, fatherList);
Human firstGrandmother = new Human("бабушка Таня", false, 67, motherList);
Human secondGrandmother = new Human("бабушка Валя", false, 61, fatherList);
Human mother = new Human("Аня", false, 41, childrenList);
motherList.add(mother);
Human father = new Human("Рома", true, 41, childrenList);
fatherList.add(father);
Human firstChild = new Human("Вова", true, 17);
Human secondChild = new Human("Олег", true, 12);
Human thirdChild = new Human("Маша", false, 24);
childrenList.add(firstChild);
childrenList.add(secondChild);
childrenList.add(thirdChild);
System.out.println(firstGrandfather);
System.out.println(firstGrandmother);
System.out.println(secondGrandfather);
System.out.println(secondGrandmother);
System.out.println(father);
System.out.println(mother);
System.out.println(firstChild);
System.out.println(secondChild);
System.out.println(thirdChild);
}
public static class Human {
//напишите тут ваш код
String name;
boolean sex;
int age;
ArrayList<Human> children;
public Human(String name, boolean sex, int age, ArrayList<Human> children) {
this.name = name;
this.sex = sex;
this.age = age;
this.children = children;
}
public Human(String name, boolean sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
}
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;
}
}
}