Чего ему еще нужно?
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
import java.util.ArrayList;
import java.util.HashMap;
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
ArrayList<Human> family = new ArrayList<>();
Human children1 = new Human("Oleg", true, 14);
Human children2 = new Human("Petya", false, 16);
Human children3 = new Human("Nastya", true, 32);
family.add(children1);
family.add(children2);
family.add(children3);
ArrayList<Human> family2 = new ArrayList<>();
Human mother = new Human("Masha", false, 44, family);
Human daddy = new Human("Oleg", true, 56, family);
family2.add(daddy);
family2.add(mother);
ArrayList<Human> family3 = new ArrayList<>();
Human Grandmother1 = new Human("Oleg", true, 14, family2);
Human Grandmother2 = new Human("Lida", true, 14, family2);
Human GrandDaddy1 = new Human("Lida", true, 14, family2);
Human GrandDaddy2 = new Human("Lida", true, 14, family2);
family3.add(GrandDaddy1);
family3.add(GrandDaddy2);
family3.add(Grandmother1);
family3.add(Grandmother2);
for (Human pair : family3) {
System.out.println(pair.toString());
}
for (Human pair : family2) {
System.out.println(pair.toString());
}
for (Human pair : family) {
System.out.println(pair.toString());
}
}
public static class Human {
//напишите тут ваш код
String name;
boolean sex;
int age;
ArrayList<Human> children = new ArrayList<>();
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;
}
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 = children;
}
}
}