Could someone explain what I am doing wrong?
package com.codegym.task.task08.task0824;
import java.util.*;
/*
Make a family
*/
public class Solution {
public static void main(String[] args) {
Human grandFather1 = new Human("gpa", true, 94);
Human grandFather2 = new Human("other gpa", true, 64);
Human grandMother1 = new Human("gma", false, 46);
Human grandMother2 = new Human("other gma", false, 76);
Human father = new Human("dad", true, 25);
Human mother = new Human("mom", false, 22);
Human child1 = new Human("child1", false, 01, "child");
Human child2 = new Human("child2", true, 00, "child");
Human child3 = new Human("child3", false, 5, "child");
child1.children = new ArrayList<>();
child2.children = new ArrayList<>();
child3.children = new ArrayList<>();
System.out.println(grandFather1);
System.out.println(grandFather2);
System.out.println(grandMother1);
System.out.println(grandMother2);
System.out.println(father);
System.out.println(mother);
System.out.println(child1);
System.out.println(child2);
System.out.println(child3);
}
public static class Human {
String name;
boolean sex;
int age;
ArrayList<Human> children = new ArrayList<Human>();
Human(String name, boolean sex, int age){
this.name = name;
this.sex = sex;
this.age = age;
}
Human(String name, boolean sex, int age, String child){
this.name = name;
this.sex = sex;
this.age = age;
children.add(this);
}
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;
}
}
}