I don't know how to continue very well,very appreciate if someone can point out what's wrong and how the code works especially how to use Human constructor and to string method to create the required variables.
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
Human children1 = new Human("wo2",false,18,null);
Human children2 = new Human("wo1",true,19,null);
Human children3 = new Human("wo",true,20,null);
ArrayList<Human> old1 = new ArrayList<Human>();
ArrayList<Human> old2 = new ArrayList<Human>();
ArrayList<Human> mom = new ArrayList<Human>();
ArrayList<Human> pa = new ArrayList<Human>();
mom.add(children1);
mom.add(children2);
mom.add(children3);
pa.add(children1);
pa.add(children2);
pa.add(children3);
Human father = new Human("mama2",false,40,pa);
Human mother = new Human("mama",false,30,mom);
old1.add(father);
old2.add(mother);
Human grandfather1 = new Human("gandie", true , 80,old1 );
Human grandfather2 = new Human("gandie2", true , 70 ,old2 );
Human grandmother1 = new Human("ganma" , false , 60,old1 );
Human grandmother2 = new Human("ganma2", false , 61,old2 );
System.out.println(grandfather1.toString());
System.out.println(grandmother1.toString());
System.out.println(grandfather2.toString());
System.out.println(grandmother2.toString());
System.out.println(father.toString());
System.out.println(mother.toString());
System.out.println(children1.toString());
System.out.println(children2.toString());
System.out.println(children3.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;
}
}
}