The last requirement is not met. Thank you!
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>();
children.add(new Human("Dao", false, 23, new ArrayList<>()));
children.add(new Human("Ca", false, 18, new ArrayList<>()));
children.add(new Human("Chau", false, 16, new ArrayList<>()));
ArrayList<Human> parents = new ArrayList<Human>();
Human dad = new Human("Ba", true, 50, children);
Human mom = new Human("Me", false, 48, children);
parents.add(dad);
parents.add(mom);
ArrayList<Human> grandparents1 = new ArrayList<Human>();
grandparents1.add(new Human("Ong noi", true, 80, parents));
grandparents1.add(new Human("Ba noi", false, 78, parents));
ArrayList<Human> grandparents2 = new ArrayList<Human>();
grandparents2.add(new Human("Ong noi", true, 88, parents));
grandparents2.add(new Human("Ba ngoai", true, 79, parents));
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;
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;
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;
}
}
}