trying for the 8 time.
please help me
package com.codegym.task.task08.task0824;
import java.util.ArrayList;
/*
Make a family
*/
public class Solution {
public static void main(String[] args) {
//write your code here
ArrayList<Human>children = new ArrayList<Human>();
Human c1 = new Human("Gugun",true,18,new ArrayList());
Human c2 = new Human("Rebecca",false,5,new ArrayList());
Human c3 = new Human("Minsei",true,2,new ArrayList());
children.add(c1);
children.add(c2);
children.add(c3);
ArrayList<Human>parents = new ArrayList<Human>();
Human f = new Human("Stephen",true,30,children);
Human m = new Human("Themboi",false,20,children);
parents.add(f);
parents.add(m);
ArrayList<Human>grandparents1 = new ArrayList<Human>();
Human gp1 = new Human("Zamtong",true,67,parents);
Human gp2 = new Human("Luonngaih",false,60,parents);
grandparents1.add(gp1);
grandparents1.add(gp2);
ArrayList<Human>grandparents2 = new ArrayList<Human>();
Human gp10 = new Human("Paosei",true,78,parents);
Human gp20 = new Human("Lhingnu",false,65,parents);
grandparents2.add(gp10);
grandparents2.add(gp20);
ArrayList<Human>family = new ArrayList<Human>();
family.addAll(grandparents1);
family.addAll(grandparents2);
family.addAll(parents);
family.addAll(children);
for(Human person : family){
System.out.println(person.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> 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;
}
}
}