Почему-то не проходит 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> human1 = new ArrayList<Human>();
ArrayList<Human> human2= new ArrayList<Human>();
ArrayList<Human> chel= new ArrayList<Human>();
Human children1 = new Human("Max", true, 17, chel);
Human children2 = new Human("Lena", false, 19, chel);
Human children3 = new Human("Natasha", true, 10, chel);
human1.add(children1);
human1.add(children2);
human1.add(children3);
Human mother = new Human("Katy", false, 30, human1);
Human father = new Human("Stepa", true, 25, human1);
human2.add(mother);
human2.add(father);
Human grandpa1 = new Human("Valera", true, 31, human2);
Human grandpa2 = new Human("kek", true, 36, human2);
Human grandma1 = new Human("Yula", false, 39, human2);
Human grandma2 = new Human("Malina", false, 32, human2);
System.out.println(grandpa1.toString());
System.out.println(grandpa2.toString());
System.out.println(grandma1.toString());
System.out.println(grandma2.toString());
System.out.println(father.toString());
System.out.println(mother.toString());
System.out.println(children1.toString());
System.out.println(children2.toString());
System.out.println(children3.toString());
//напишите тут ваш код
}
public static class Human {
String name;
boolean sex;
int age;
ArrayList<Human> children;
Human(String name, boolean sex, int age, ArrayList<Human> children) {
this.name = name;
this.sex = sex;
this.age = age;
this.children = children;
}
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;
}
}
}