package com.codegym.task.task08.task0824;
import java.util.ArrayList;
/*
Make a family

*/

public class Solution {
    public static void main(String[] args) {
        Human grandf1 = new Human(true, 78, "Gheorghe", new ArrayList<Human>());
        Human grandf2 = new Human(true, 66, "Marin", new ArrayList<Human>());

        Human grandm1 = new Human(false, 78, "Angela", new ArrayList<Human>());
        Human grandm2 = new Human(false, 66, "Dorina", new ArrayList<Human>());

        Human mother= new Human(false, 67, "Monica", new ArrayList<Human>());
        Human father = new Human(true, 70, "Cristian", new ArrayList<Human>());

        Human child1 = new Human(true, 37, "Tudor", new ArrayList<Human>());
        Human child2 = new Human(true, 44, "Iulian", new ArrayList<Human>());
        Human child3 = new Human(false, 38, "Maria", new ArrayList<Human>());

        ArrayList <Human> children = new ArrayList<Human>();

        father.children.add(child1);
        father.children.add(child2);
        father.children.add(child3);

        mother.children.add(child1);
        mother.children.add(child2);
        mother.children.add(child3);

        grandf1.children.add(mother);
        grandf2.children.add(mother);

        grandf1.children.add(father);
        grandf2.children.add(father);

        grandm1.children.add(mother);
        grandm2.children.add(mother);

        grandm1.children.add(father);
        grandm2.children.add(father);

        System.out.println(grandf1.toString());
        System.out.println(grandf2.toString());

        System.out.println(grandm1.toString());
        System.out.println(grandm2.toString());

        System.out.println(father.toString());
        System.out.println(mother.toString());

        System.out.println(child1.toString());
        System.out.println(child2.toString());
        System.out.println(child3.toString());

        for (Human child : children) {
            System.out.println(child);
        }
    }

    public static class Human {
        String name;
        boolean sex;
        int age;
        ArrayList<Human> children;

        public Human(boolean sex, int age, String name, ArrayList<Human> children) {
            this.sex = sex;
            this.age = age;
            this.name = name;
            this.children = children;
        }


        public String toString() {
            String text = "";
            text += "Name: " + this.name;
            text += ", sex: " + (this.sex ? "male" : "female");
            text += ", age: " + this.age;

            int childCount = this.children.size();
            if (childCount > 0) {
                text += ", children: " + this.children.get(0).name;

                for (int i = 1; i < childCount; i++) {
                    Human child = this.children.get(i);
                    text += ", " + child.name;
                }
            }
            return text;
        }
    }

}