Output is correct but validation does not pass . Whats wrong here?
package com.codegym.task.task08.task0824;
/*
Make a family
*/
import java.util.*;
public class Solution {
public static void main(String[] args) {
//write your code here
Human child1 = new Human("Bill", true, 15, new ArrayList<Human>());
Human child2 = new Human("Emma", false, 10,new ArrayList<Human>());
Human child3 = new Human("Bob", true, 5, new ArrayList<Human>());
ArrayList<Human> children = new ArrayList<Human>();
children.add(child1);
children.add(child2);
children.add(child3);
Human mother = new Human("Berta", false, 35, children);
Human father = new Human("Billy", true, 40, children);
ArrayList<Human> chFather = new ArrayList<Human>();
chFather.add(father);
ArrayList<Human> chMother = new ArrayList<Human>();
chMother.add(mother);
Human grF1 = new Human("Fill", true, 70, chFather);
Human grM1 = new Human("Molly", false, 60, chFather);
Human grF2 = new Human("Tom", true, 60, chMother);
Human grM2 = new Human("Sally", false, 55, chMother);
ArrayList<Human> family = new ArrayList<Human>(Arrays.asList(grF1, grF2, grM1, grM2, father, mother, child1, child2, child3));
System.out.println(family.toString());
}
public static class Human {
//write your code here
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 += "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;
}
}
}