Пожскажите 5 пункт.
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
ArrayList<Human> noname = new ArrayList<Human>();
ArrayList<Human> gr = new ArrayList<Human>();
ArrayList<Human> children = new ArrayList<Human>();
ArrayList<Human> parents = new ArrayList<Human>();
ArrayList<Human> parents2 = new ArrayList<Human>();
Human grfather1 = new Human("Вася", true, 55, parents);
Human grfather2 = new Human("Сережа", true, 56, parents2);
Human grmather1 = new Human("Женя", false, 50, parents);
Human grmather2 = new Human("Жанна", false, 51, parents2);
Human father = new Human("Саня", true, 30, children);
Human mather = new Human("Соня", false, 25, children);
Human child1 = new Human("Петруша", true, 10, noname);
Human child2 = new Human("Валюша", false, 9, noname);
Human child3 = new Human("Глаша", false, 3, noname);
gr.add(grfather1);
gr.add(grfather2);
gr.add(grmather1);
gr.add(grmather2);
parents.add(father);
parents2.add(mather);
children.add(child1);
children.add(child2);
children.add(child3);
System.out.println(gr.toString());
System.out.println(parents.toString());
System.out.println(parents2.toString());
System.out.println(children.toString());
}
public static class Human {
//напишите тут ваш код
String name;
boolean sex;
int age;
ArrayList<Human> children;
public Human (String name, boolean sex, int age, ArrayList children) {
this.name = name;
this.sex = sex;
this.age = age;
this.children = children;
}
/*public Human (String name, boolean sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
} */
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;
}
}
}