?
package com.codegym.task.task08.task0824;
import java.util.*;
/*
Make a family
*/
public class Solution {
public static void main(String[] args) {
//write your code here
ArrayList<Human> c1 = new ArrayList<Human>();
ArrayList<Human> c2 = new ArrayList<Human>();
ArrayList<Human> c3 = new ArrayList<Human>();
Human c = new Human("Ronita",false,10,null);
c1.add(c);
Human f = new Human("Raj",true,20,c1);
Human m = new Human("Kanika",false,20,c1);
c2.add(f);
Human gf1 = new Human("Remo",true,40,c2);
c3.add(m);
Human gf2 = new Human("Dharmesh",true,40,c3);
Human gm1 = new Human("Lina",false,40,c2);
Human gm2 = new Human("Tina",false,40,c3);
System.out.println(gf1.toString());
System.out.println(gf2.toString());
System.out.println(gm1.toString());
System.out.println(gm2.toString());
System.out.println(f.toString());
System.out.println(m.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, ArrayList<Human> child)
{
this.name = name;
this.sex = sex;
this.age = age;
this.children = child;
}
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;
}
}
}