output seems to be correct, please advise.
package com.codegym.task.task08.task0824;
import java.util.*;
public class Solution {
public static void main(String[] args) {
//write your code here
Human c1=new Human("child1",true,10,new ArrayList<>());
Human c2=new Human("child2",false,15,new ArrayList<>());
Human c3=new Human("child3",true,12,new ArrayList<>());
ArrayList<Human> grandkids=new ArrayList<>();
grandkids.add(c1);grandkids.add(c2);grandkids.add(c3);
Human mom=new Human("mom",false,50,grandkids);
Human dad=new Human("dad",true,55,grandkids);
ArrayList<Human> kids=new ArrayList<>();
kids.add(mom);kids.add(dad);
Human gp1=new Human("gp1",true,100,kids);
Human gp2=new Human("gp2",true,101,kids);
Human gm1=new Human("gm1",false,100,kids);
Human gm2=new Human("gm2",false,101,kids);
System.out.println(gp1.toString());
System.out.println(gp2.toString());
System.out.println(gm1.toString());
System.out.println(gm2.toString());
System.out.println(dad.toString());
System.out.println(mom.toString());
System.out.println(c1.toString());
System.out.println(c2.toString());
System.out.println(c3.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 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;
}
}
}