Не могу понять почему не видит переменную name
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
ArrayList<Human> children = new ArrayList<>();
ArrayList<Human> children2 = new ArrayList<>();
Human child1 = new Human("Bill",true , 12,children2 );
children.add(child1);
Human child2 = new Human("Rosa",false , 11,children2 );
children.add(child2);
Human child3 = new Human("Chak",true , 5,children2 );
children.add(child3);
// Human human = new Human("Stiv2" ,true ,83 );
Human humanFather = new Human("Stiv" ,true ,43 ,children);
Human humanMother = new Human("Jolly" ,false ,23 ,children);
ArrayList<Human> Father = new ArrayList<>();
Father.add(humanFather);
ArrayList<Human> Mother = new ArrayList<>();
Mother.add(humanMother);
Human humanGf1 = new Human("Stivd" ,true ,53 ,Father);
Human humanGm1 = new Human("Stivk" ,false ,73 ,Father);
Human humanGf2 = new Human("Stivq" ,true ,73 ,Mother);
Human humanGm2 = new Human("Stivr" ,false ,63 ,Mother);
System.out.println(humanFather);
}
public static class Human {
//напишите тут ваш код
String name;
boolean sex;
int age;
ArrayList children;
// public Human (String name)
// {
// this.name = name;
// }
public Human (String name, boolean sex, int age, ArrayList<Human> children)
{
this.name = name;
this.sex = sex;
this.age = age;
this.children = children;
// this.mother = mother;
}
// public Human(String name, boolean sex, int 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;
}
}
}