😥
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
public class Solution {
public static void main(String[] args) {
Human childB = new Human("Billy", true, 12);
Human childG = new Human("Anny", false, 9);
Human childB2 = new Human("Luck", true, 11);
ArrayList<Human> child = new ArrayList<>(Arrays.asList(childB,childG,childB2));
Human father = new Human("Dick", true, 26, childB, childG, childB2);
Human mother = new Human("Linda", false, 22, childB, childG, childB2);
ArrayList<Human> par = new ArrayList<>(Arrays.asList(mother,father));
Human grandFather = new Human("Jack", true, 65,mother);
Human grandFather1 = new Human("Donald", true, 65,father);
Human grandMother = new Human("JackWife", false, 55,mother);
Human grandMother1 = new Human("DonaldWife", false, 57,father);
ArrayList<Human> old = new ArrayList<>(Arrays.asList(grandFather, grandFather1, grandMother, grandMother1));
ArrayList <Human> family = new ArrayList<>();
family.addAll(child);
family.addAll(par);
family.addAll(old);
for (Human x : family)
{
System.out.println(x.toString());
}
}
public static class Human {
String name;
boolean sex;
int age;
ArrayList<Human> children;
Human(String name, boolean sex, int age, Human...array){
this.name = name;
this.sex = sex;
this.age = age;
Collections.addAll(this.children, array);
}
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;
}
}
}