или я не правильно понял задачу
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) {
//напишите тут ваш код
ArrayList<Object> family = new ArrayList<Object>();
ArrayList<Human> children1 = new ArrayList<Human>();
ArrayList<Human> children2 = new ArrayList<Human>();
ArrayList<Human> children3 = new ArrayList<Human>();
Human child1 = new Human("чилд1", true, 5);
Human child2 = new Human("чилд2", true, 5);
Human child3 = new Human("чилд2", true, 5);
Human mather = new Human("mather", false, 30, children3);
Human father = new Human("father", true, 30, children3);
Human baba1 = new Human("baba1", false, 60, children1);
Human ded1 = new Human("ded1", true, 60, children1);
Human baba2 = new Human("baba2", false, 60, children2);
Human ded2 = new Human("ded2", true, 60, children2);
children1.add(mather);
children2.add(father);
children3.add(child1);
children3.add(child2);
children3.add(child3);
/*
System.out.println(ded1.toString());
System.out.println(ded2.toString());
System.out.println(baba1.toString());
System.out.println(baba2.toString());
System.out.println(father.toString());
System.out.println(mather.toString());
System.out.println(child1.toString());
System.out.println(child2.toString());
System.out.println(child3.toString());
*/
family.add(ded1);
family.add(ded2);
family.add(baba1);
family.add(baba2);
family.add(father);
family.add(mather);
family.add(children3);
System.out.println(family.toString());
}
public static class Human {
//напишите тут ваш код
public String name;
public boolean sex;
public int age;
public ArrayList<Human> children = new ArrayList<Human>();
public Human (String name, boolean sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
}
public Human (String name, boolean sex, int age, ArrayList<Human> children) {
this.name = name;
this.sex = sex;
this.age = age;
this.children.addAll(children);
// this.children = new ArrayList<Human>(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;
}
}
}