Any ideas? Help will be much appreciated :)
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
Human C1 = new Human("Thomas",true,21, new ArrayList<Human>());
Human C2 = new Human("Michelle",false,23, new ArrayList<Human>());
Human C3 = new Human("Casey",false,19, new ArrayList<Human>());
ArrayList<Human> children = new ArrayList<>(), father = new ArrayList<>(), mother = new ArrayList<>(), grandparents = new ArrayList<>();
children.add(C1); children.add(C2); children.add(C3);
Human M1 = new Human("Samita",false,56,children);
Human F1 = new Human("Jatin",true,62,children);
father.add(F1); mother.add(M1);
Human GM1 = new Human("Subhani",false,70,father);
Human GF1 = new Human("Yogindar",true,77,father);
Human GM2 = new Human("Meena",false,69,mother);
Human GF2 = new Human("Prajosh",true,76,mother);
grandparents.add(GM1); grandparents.add(GM2); grandparents.add(GF1); grandparents.add(GF2);
System.out.println(children.toString());
System.out.println(father.toString());
System.out.println(mother.toString());
System.out.println(grandparents.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> 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;
}
}
}