А?
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
ArrayList <Human> children = new ArrayList<>();
children.add(new Human ("Pol",true,13));
children.add(new Human ("Jack",true,15));
children.add(new Human ("Bill",true,14));
ArrayList <Human> parents = new ArrayList<>();
parents.add(new Human("Tom",true,42));
parents.add(new Human("Maria",false,32));
ArrayList <Human> gparents1 = new ArrayList<>();
gparents1.add(new Human("Steel",true,86));
gparents1.add(new Human("Ann",false,77));
ArrayList <Human> gparents2 = new ArrayList<>();
gparents2.add(new Human("Ann",true,77));
gparents2.add(new Human("Troy",false,77));
for (int i = 0; i < children.size(); i++) {
System.out.println(children.get(i).toString());
}
for (int i = 0; i < parents.size(); i++) {
System.out.println(parents.get(i).toString());
}
for (int i = 0; i < gparents1.size(); i++) {
System.out.println(gparents1.get(i).toString());
}
for (int i = 0; i < gparents2.size(); i++) {
System.out.println(gparents2.get(i).toString());
}
}
public static class Human {
String name;
boolean sex;
int age;
ArrayList <Human> children = new ArrayList<>();
Human(String name,boolean sex, int age){
this.name = name;
this.sex = sex;
this.age = age;
}
Human(String name, boolean sex, int age, ArrayList<Human> children){
this.name = name;
this.sex = sex;
this.age = age;
this.children = 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;
}
}
}