На печать выводит 0 лет.
Если выводит на печать объект выводит "Имя: null, пол: женский, возраст: 0"
В чем моя ошибка?
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.List;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
ArrayList<Human> children1 = new ArrayList<Human>();
ArrayList<Human> children2 = new ArrayList<Human>();
ArrayList<Human> children3 = new ArrayList<Human>();
Human son1 = new Human("Сын1", true, 15);
Human son2 = new Human("Сын2", true, 7);
Human daughter1 = new Human("Дочь", false, 12);
children1.add(son1);
children1.add(son2);
children1.add(daughter1);
Human father = new Human("Отец", true, 35, children1);
Human mother = new Human("Мать", false, 33, children1);
children2.add(father);
children3.add(mother);
Human grandfather1 = new Human("Дедушка1", true, 60, children2);
Human grandmother1 = new Human("Бабушка1", false, 55, children2);
Human grandfather2 = new Human("Дедушка2", true, 58, children3);
Human grandmother2 = new Human("Бабушка2", false,53, children3);
System.out.println(grandfather1.age);
// System.out.println(son2.toString());
// System.out.println(daughter1.toString());
// System.out.println(father.toString());
// System.out.println(mother.toString());
}
public static class Human {
//напишите тут ваш код
String name;
boolean sex;
int age;
ArrayList <Human> children = new ArrayList<>();
Human(String name, boolean sex, int age){
name=this.name;
sex=this.sex;
age=this.age;
}
Human(String name, boolean sex, int age, ArrayList<Human> children){
name=this.name;
sex=this.sex;
age=this.age;
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;
}
}
}