Всем привет.
Ребята, помогите пожалуйста.
Выдает ошибку.
Мозг сломал полностью.)
Может что-то не понимаю?
Направьте мысли в нужном направлении.
Спасибо.
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.Collections;
import java.util.*;
import java.io.*;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
ArrayList<Human> child0 = new ArrayList<>();
ArrayList<Human> child = new ArrayList<>();
Human child1 = new Human ("Vasya", 3, true, child0);
child.add(child1);
Human child2 = new Human ("Petya", 6, true, child0);
child.add(child2);
Human child3 = new Human ("Olya", 14, false, child0);
child.add(child3);
ArrayList<Human> mother = new ArrayList<>();
ArrayList<Human> father = new ArrayList<>();
Human mother1 = new Human ("Valya", 40, false, child);
mother.add(mother1);
Human father1 = new Human ("Oleg", 41, true, child);
father.add(father1);
Human grandmother1 = new Human ("Julya", 64, false, mother);
Human grandfather1 = new Human ("Sasha", 65, true, mother);
Human grandmother2 = new Human ("Zina", 63, false, father);
Human grandfather2 = new Human ("Dima", 67, true, father);
System.out.println(grandfather1);
System.out.println(grandfather2);
System.out.println(grandmother1);
System.out.println(grandmother2);
System.out.println(father);
System.out.println(mother);
System.out.println(child1);
System.out.println(child2);
System.out.println(child3);
}
public static class Human {
String name;
int age;
boolean sex;
ArrayList<Human> children;
public Human (String name, int age, boolean sex, ArrayList<Human> children) {
name = this.name;
age = this.age;
sex = this.sex;
children = this.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;
}
}
}