Can anyone help with the last objective?
package com.codegym.task.task08.task0824;
/*
Make a family
*/
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
//write your code here
ArrayList<Human> children = new ArrayList<Human>();
children.add(new Human("Ala", true, 3));
children.add(new Human("Roza", true, 2));
children.add(new Human("Sylwek", false, 2));
ArrayList<Human> parents = new ArrayList<Human>();
parents.add(new Human("Adam", false, 33, children));
parents.add(new Human("Paulina", true, 33, children));
ArrayList<Human> grandparents = new ArrayList<Human>();
grandparents.add(new Human("Jacek", false, 60, parents));
grandparents.add(new Human("Leszek", false, 61, parents));
grandparents.add(new Human("Ela", true, 60, parents));
grandparents.add(new Human("Gosia", true, 60, parents));
for (Human child : children) {
System.out.println(child);
}
for (Human parent : parents) {
System.out.println(parent);
}
for (Human grandparent : grandparents) {
System.out.println(grandparent);
}
}
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) {
this.name = name;
this.sex = sex;
this.age = age;
}
public Human(String name, boolean sex, int age, ArrayList<Human> children) {
this.name = name;
this.sex = sex;
this.age = age;
this.children = children;
}
public String toString() {
String text = "";
text += "Name: " + this.name;
text += ", sex: " + (this.sex ? "male" : "female");
text += ", age: " + this.age;
if(this.children != null) {
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;
}
}
}