почему не добавляэт обект в масив?
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) {
//напишите тут ваш код
}
public static class Human {
//напишите тут ваш код
String name;
boolean sex;
int age;
ArrayList<Human> children = new ArrayList<>();
Human grendfather = new Human();
Human grendfather2 = new Human();
Human grendmather = new Human();
Human grendmather2 = new Human();
Human father = new Human();
Human mather = new Human();
Human child1 = new Human();
Human child2 = new Human();
Human child3 = new Human();
children.add(child1);
children.add(child2);
children.add(child3);
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;
}
}
}