Seems to output is good but can't pass last condition :\ Anybody can help?
package com.codegym.task.task08.task0824;
import java.util.ArrayList;
import java.util.Collections;
/*
Make a family
*/
public class Solution {
public static void main(String[] args) {
ArrayList<Human>childrenOlder = new ArrayList<Human>();
ArrayList<Human>childrenYounger = new ArrayList<Human>();
Human grandfather1 = new Human("Janusz", 78, true,childrenOlder);
Human grandfather2 = new Human("Paweł", 88, true);
Human grandmother1 = new Human("Anka", 77, false, childrenOlder);
Human grandmother2 = new Human("Genowefa", 72, false);
Human father = new Human("Janusz", 40, true, childrenYounger);
Human mother = new Human("Ola", 50, true, childrenYounger);
Human child1= new Human("Janek", 20, true);
Human child2 = new Human("Bronek", 20, true);
Human child3 = new Human("Mietek", 20, true);
Collections.addAll(childrenYounger,child1,child2,child3);
Collections.addAll(childrenOlder,father,mother);
System.out.println(grandfather1.toString());
System.out.println(grandfather2.toString());
System.out.println(grandmother1.toString());
System.out.println(grandmother2.toString());
System.out.println(father.toString());
System.out.println(mother.toString());
System.out.println(child1.toString());
System.out.println(child2.toString());
System.out.println(child3.toString());
}
public static class Human {
String name;
int age;
boolean sex;
ArrayList<Human> children = new ArrayList<>();
Human(String name, int age, boolean sex,ArrayList<Human>children){
this.name=name;
this.age=age;
this.sex=sex;
this.children=children;
}
Human(String name, int age, boolean sex){
this.name=name;
this.age=age;
this.sex=sex;
}
public String toString() {
String text = "";
text += "Name: " + this.name;
text += ", sex: " + (this.sex ? "male" : "female");
text += ", age: " + this.age;
int childCount = this.children.size();
if (childCount > 0) {
text += ", children: " + this.children.get(0).name;
for (int i = 1; i < childCount; i++) {
Human child = this.children.get(i);
text += ", " + child.name;
}
}
return text;
}
}
}