why the last condition is not satisfying ??
package com.codegym.task.task08.task0824;
/*
Make a family
*/
import java.util.*;
public class Solution {
public static void main(String[] args) {
ArrayList<Human> child1 = new ArrayList<>();
ArrayList<Human> child2 = new ArrayList<>();
ArrayList<Human> child3 = new ArrayList<>();
Human c1 = new Human("Ali",true,21,null);
child1.add(c1);
Human c2 = new Human("nimra",false,20,null);
child1.add(c2);
Human c3 = new Human("kamran",true,22,null);
child1.add(c1);
Human f1 = new Human("ahmed",true,30,child1);
child2.add(f1);
Human m1 = new Human("leeza",false,28,child1);
child3.add(m1);
Human gf1 = new Human("Aziz",true,70,child2);
Human gf2 = new Human("wazeer",true,65,child3);
Human gm1 = new Human("zainab",false,67,child2);
Human gm2 = new Human("zahra",false,55,child3);
System.out.println(gf1.toString());
System.out.println(gf2.toString());
System.out.println(gm1.toString());
System.out.println(gm2.toString());
System.out.println(f1.toString());
System.out.println(m1.toString());
System.out.println(child1.toString());
System.out.println(child2.toString());
System.out.println(child3.toString());
}
public static class Human {
//write your code here
String name;
boolean sex;
int age;
ArrayList<Human> children = new ArrayList<Human>();
public Human(String name,boolean sex,int age,ArrayList<Human> c)
{
this.name=name;
this.sex=sex;
this.age=age;
this.children=c;
}
public String toString() {
String text = "";
text += "Name: " + this.name;
text += ", sex: " + (this.sex ? "male" : "female");
text += ", age: " + this.age;
int childCount;
if(children == null)
childCount = 0;
else
childCount = 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;
}
}
}