Добрый день.
Помогите пожалуйста понять где ошибка.
Я упорно не вижу, в чем дело, ибо последний пункт выполнен и вывод соответствует условию.
Заранее спасибо!
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
Human[] humans = new Human[9];
humans[0]= new Human("GranDad1", true, 58);
humans[1]= new Human("GranDad2", true, 65);
humans[2]= new Human("GranMa1", false, 64);
humans[3]= new Human("GranMa2", false, 56);
humans[4]= new Human("Dad", true, 40, humans[0], humans[1],humans[2]);
humans[5]= new Human("Mom", false, 35, humans[0], humans[1],humans[2]);
humans[6]= new Human("Child1", true, 10);
humans[7]= new Human("Child2", true, 10);
humans[8]= new Human("Child3", true, 10);
for(int i=0; i<humans.length; i++){
System.out.println(humans[i].toString());
}
//напишите тут ваш код
}
public static class Human {
public String name;
public boolean sex;
public int age;
public ArrayList<Human> children=new ArrayList<>();
public Human(String name, boolean sex, int age, Human...human){
this.name = name;
this.sex = sex;
this.age = age;
this.children = children;
Collections.addAll(this.children,human);
}
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;
}
}
}