Fourth Requirement is not matching
package com.codegym.task.task08.task0824;
/*
Make a family
*/
import java.util.*;
public class Solution {
public static void main(String[] args) {
ArrayList<Human> Son_Girl = new ArrayList<> ();
ArrayList<Human> GF_GM = new ArrayList<> ();
ArrayList<Human> Father_Mother = new ArrayList<> ();
ArrayList<Human> Motther = new ArrayList<> ();
Human son = new Human("Son1",true,15,null);
Human Son1 = new Human("Son2",true,13,null);
Human Daughter = new Human("Daughter",false,16,null);
Human sona = new Human("Son1a",true,15,null);
Human Son1a = new Human("Son2a",true,13,null);
Human Daughtera = new Human("Daughtera",false,16,null);
Son_Girl.add(Son1);
Son_Girl.add(son);
Son_Girl.add(Daughter);
Motther.add(sona);
Motther.add(Son1a);
Motther.add(Daughtera);
Human Father = new Human("father",true,30,Son_Girl);
Human Mother = new Human("mother",false,32,Motther);
Father_Mother.add(Father);
Human GF1 = new Human("GF1",true,50,Father_Mother);
Human GM1 = new Human("GM1",false,45,Father_Mother);
GF_GM.add(Mother);
Human GF2 = new Human("GF2",true,50,GF_GM);
Human GM2 = new Human("GM2",false,45,GF_GM);
System.out.println(GF2);
System.out.println(GM2);
System.out.println(GF1);
System.out.println(GM1);
System.out.println(Father);
System.out.println(Mother);
}
public static class Human {
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;
}
}
}