package com.javarush.task.task08.task0824; import java.util.*; /* Собираем семейство */ public class Solution { public static void main(String[] args) { Human eldos = new Human("eldos", true, 17); Human arlen = new Human("arlen", true, 17); Human adilet = new Human("adilet", true, 17); System.out.println(eldos.toString()); System.out.println(arlen.toString()); System.out.println(adilet.toString()); ArrayList<Human> kid3 = new ArrayList<Human>(); kid3.add(eldos); kid3.add(arlen); kid3.add(adilet); Human alibek = new Human("alibek", true, 40, kid3); Human shahri = new Human("shahri", false, 40, kid3); System.out.println(alibek.toString()); System.out.println(shahri.toString()); ArrayList<Human> kid1 = new ArrayList<Human>(); kid1.add(alibek); Human grandfa = new Human("dimok", true, 70, kid1); Human grandma = new Human("amina", false, 70, kid1); System.out.println(grandfa.toString()); System.out.println(grandma.toString()); ArrayList<Human> kid2 = new ArrayList<Human>(); kid2.add(shahri); Human grandfas = new Human("erbol", true, 70, kid2); Human grandmas = new Human("ess", true, 70, kid2); System.out.println(grandfas.toString()); System.out.println(grandmas.toString()); } public static class Human { public String name; public boolean sex; public int age; public ArrayList<Human> children; 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; } } }