package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
Human child1 = new Human("Danya", true, 15, null);
Human child2 = new Human("banya", true, 15, null);
Human child3 = new Human("Danya", true, 15, null);
Human grandfather1 = new Human("Vanya",true, 68, new ArrayList<>(Arrays.asList(child1, child2, child3)));
Human grandfather2 = new Human("Danya", true, 68, new ArrayList<>(Arrays.asList(child1, child2, child3)));
Human grandmother1 = new Human("Tanya", false, 68, new ArrayList<>(Arrays.asList(child1, child2, child3)));
Human grandmother2 = new Human("Manya", false, 68, new ArrayList<>(Arrays.asList(child1, child2, child3)));
Human father = new Human("Danya", true, 45, new ArrayList<>(Arrays.asList(child1, child2, child3)));
Human mother = new Human("Varya", false, 45, new ArrayList<>(Arrays.asList(child1, child2, child3)));
}
public static class Human {
public String name;
public boolean sex;
public int age;
ArrayList<Human> children = new ArrayList<>();
public Human(String name,boolean sex, int age, ArrayList<Human> children) {
this.name = name;
this.sex = sex;
this.age = age;
this.children = children;
System.out.println(children.toString());
}
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;
}
}
}
Ты ничего не выводишь на экранТы выводишь на экран список детей объекта при создании. Вместо этого нужно выводить сам объект. Из метода main. А конструктор должен только создавать объекты, а не выводить их на экран. 2. У тебя дедушки и бабушки являются родителями не папы и мамы соответственно, а внуков.