Я не понимать, пожалуйста помогите, заранее спасибо)
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
/**
* Собираем семейство
* 1. Создай класс Human с полями имя (String), пол (boolean), возраст (int), дети (ArrayList<Human>).
* 2. Создай объекты и заполни их так, чтобы получилось: два дедушки, две бабушки, отец, мать, трое детей.
* 3. Выведи все объекты Human на экран (Подсказка: используй метод toString() класса Human).
*
* Требования:
* 1. Программа должна выводить текст на экран.
* 2. Класс Human должен содержать четыре поля.
* 3. Класс Human должен содержать один метод.
* 4. Класс Solution должен содержать один метод.
* 5. Программа должна создавать объекты и заполнять их так, чтобы получилось: два дедушки, две бабушки, отец, мать, трое детей и выводить все объекты Human на экран.
*/
public class Solution
{
public static void main(String[] args)
{
ArrayList<Human> family2 = new ArrayList<>();
Human children1 = new Human("Artem", true, 14);
Human children2 = new Human("Vanya", true, 11);
Human children3 = new Human("Olesya", false, 8);
ArrayList<Human> family1 = new ArrayList<>();
Human father = new Human("Kolya", true, 43, family2 );
Human mother = new Human("Vera", false, 38, family2);
ArrayList<Human> family = new ArrayList<>();
Human grandFather1 = new Human("Vasya", true, 65, family1);
Human grandFather2 = new Human("Vova", true, 71, family1 );
Human grandMother1 = new Human("Maria", false, 60, family1);
Human grandMother2 = new Human("Nina", false, 66, family1);
family.add(grandFather1);
family.add(grandFather2);
family.add(grandMother1);
family.add(grandMother2);
family1.add(father);
family1.add(mother);
family2.add(children1);
family2.add(children2);
family2.add(children3);
for(Human pair: family)
{
System.out.println(pair);
}
for(Human pair: family1)
{
System.out.println(pair);
}
for(Human pair: family2)
{
System.out.println(pair);
}
//напишите тут ваш код
}
public static class Human
{
String name;
boolean sex;
int age;
ArrayList<Human> children = new ArrayList<>();
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;
}
//напишите тут ваш код
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;
}
}
}