спасибо.
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> net = new ArrayList<>();
ArrayList<Human> deti = new ArrayList<>();
ArrayList<Human> roditeli = new ArrayList<>();
ArrayList<Human> roditeli2 = new ArrayList<>();
Human d1 = new Human("a", false, 80, roditeli);
Human d2 = new Human("m", false, 85, roditeli2);
Human b1 = new Human("a", true, 80, roditeli);
Human b2 = new Human("c", true, 80, roditeli2);
Human p = new Human("a", false, 50, deti);
Human m = new Human("j", true, 49, deti);
Human r1 = new Human("a", false, 20, net);
Human r2 = new Human("s", false, 19, net);
Human r3 = new Human("g", true, 18, net);
System.out.println(d1.toString());
System.out.println(d2.toString());
System.out.println(b1.toString());
System.out.println(b2.toString());
System.out.println(p.toString());
System.out.println(m.toString());
System.out.println(r1.toString());
System.out.println(r2.toString());
System.out.println(r3.toString());
}
public static class Human {
//напишите тут ваш код
String name;
boolean sex;
int age;
ArrayList<Human> children;
public Human(String name, boolean sex, int age, ArrayList<Human> 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;
}
}
}