I need to have four fields in the Human class and i have only four fields still I dont pass. Where is the Problem?
package com.codegym.task.task08.task0824;
/*
Make a family
*/
import java.util.*;
public class Solution {
public static void main(String[] args) {
//write your code here
ArrayList<Human> childs = new ArrayList<Human>();
Human c1 = new Human("Marie",false,15,childs);
Human c2 = new Human("Marie",false,15,childs);
Human c3 = new Human("Marie",false,15,childs);
ArrayList<Human> childs1 = new ArrayList<Human>();
childs1.add(c1);childs1.add(c2);childs1.add(c3);
Human m = new Human("Marie",false,15,childs1);
Human d = new Human("Marie",true,15,childs1);
ArrayList<Human> M1 = new ArrayList<Human>();
ArrayList<Human> D1 = new ArrayList<Human>();
M1.add(m);D1.add(d);
Human gd1 = new Human("Marie",true,15,M1);
Human gm1 = new Human("Marie",false,15,M1);
Human gd2 = new Human("Marie",true,15,D1);
Human gm2 = new Human("Marie",false,15,D1);
ArrayList<Human> humans = new ArrayList<Human>();
humans.add(c1);humans.add(c2);humans.add(c3);humans.add(m);humans.add(d);
humans.add(gd1);humans.add(gm1);humans.add(gd2);humans.add(gm2);
try{for(Human human : humans){System.out.println(human.toString());}}
catch(Exception e){System.out.println(true);}
//System.out.println(c1.toString());
}
public static class Human {
//write your code here
private String name;
private boolean sex;
private int age;
private 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;
}
}
}