It looks right to me but it's saying that when I initialize the new human the listed children aren't legit variables
package com.codegym.task.task08.task0824;
import java.util.*;
/*
Make a family
*/
public class Solution {
public static void main(String[] args) {
//write your code here
ArrayList<Human> family = new ArrayList<Human>();
Human grandpa = new Human("jo", true, 88, dad);
Human grandma = new Human("ja", false, 87, dad);
Human grandpa2 = new Human("je", true, 88, mom);
Human grandma2 = new Human("ju", false, 87, mom);
Human dad = new Human("jon", true, 33, son,daughter,daughter2);
Human mom = new Human("jan", false, 31, son,daughter,daughter2);
Human son = new Human("joan", true, 18);
Human daughter = new Human("jaon", false, 14);
Human daughter2 = new Human("joon", false, 14);
family.add(grandpa);
family.add(grandma);
family.add(grandpa2);
family.add(grandma2);
family.add(dad);
family.add(mom);
family.add(son);
family.add(daughter);
family.add(daughter2);
System.out.println(family.toString());
}
public static class Human {
public String name;
public boolean sex;
public int age;
public ArrayList<Human> children;
//write your code here
public Human(String name, boolean sex, int age, Human child){
this.name = name;
this.sex = sex;
this.age = age;
this.children.add(child);
}
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;
}
}
}