I read other help questions but still the problem.
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>();
ArrayList<Human> old = new ArrayList<Human>();
// initlaize child
Human child1 = new Human("child1",true,15);
Human child2 = new Human("child2",false,20);
Human child3 = new Human("child3",true,10);
// add child to arraylist
children.add(child1);
children.add(child2);
children.add(child3);
// intilize father & mother
Human father = new Human("father",true,30,children);
Human mother = new Human("mother",false,29,children);
// add Father & mother to array list
old.add(father);
old.add(mother);
//inistalize grfather and mother
Human grandFathe1 = new Human("gf1",true,60,old);
Human grandMother1 = new Human("gm", false,55,old);
Human grandFathe2 = new Human("gf2",true,61,old);
Human grandMother2 = new Human("gm2", false,54,old);
System.out.println(grandFathe1.toString());
System.out.println(grandFathe2.toString());
System.out.println(grandMother1.toString());
System.out.println(grandMother2.toString());
System.out.println(father.toString());
System.out.println(mother.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 children){
this.name = name;
this.sex = sex;
this.age = age;
this.children = children;
}
public Human(String name, Boolean sex, int age){
this.name = name;
this.sex = sex;
this.age = age;
}
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;
}
}
}