Hi, I am not too sure whats the problem if anyone could help
package com.codegym.task.task08.task0824;
/*
Make a family
2. Create and populate objects so that we end up with:
two grandfathers, two grandmothers, one father, one mother, and three children.
3. Display all the Human objects (Hint: use the Human class's toString() method).
Requirements:
1. The program should display text on the screen.
3. The Human class must have one method.
4. The Solution class must have one method.
5. The program should create objects and fill them with data to get two grandfathers, two grandmothers, one father,
one mother, and three children. Then it should display all the Human objects on the screen.
*/
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
Human human = new Human("mina",true,33,new Human("nabil"),
new Human("nevet"),new Human("kamel"),new Human("anis"),
new Human("kamelia"),new Human("victoria"),3);
human.children.add(new Human("andrew"));
human.children.add(new Human("ramy"));
human.children.add(new Human("donna"));
System.out.println(human);
}
public static class Human {
private String name;
private boolean sex;
private int age;
ArrayList<Human> children ;
private Human grandFather1;
private Human grandFather2;
private Human grandMother1;
private Human grandMother2;
private Human father;
private Human mother;
private int childCount;
/*Human(String name,boolean sex, int age){
this.name = name;
this.sex = sex;
this.age = age;
}*/
Human(String name){
this.name = name;
}
Human(String name,boolean sex, int age, Human father, Human mother,
Human grandFather1, Human grandFather2, Human grandMother1, Human grandMother2, int childCount ){
this.name = name;
this.sex = sex;
this.age = age;
this.father = father;
this.mother = mother;
this.grandFather1 = grandFather1;
this.grandFather2 = grandFather2;
this.grandMother1 = grandMother1;
this.grandMother2 = grandMother2;
this.father = father;
this.mother = mother;
children = new ArrayList<>(childCount);
}
@Override
public String toString() {
String text = "";
text += "Name: " + this.name;
text += ", sex: " + (this.sex ? "male" : "female");
text += ", age: " + this.age;
text += ", grandfather: " + this.grandFather1;
text += ", grandfather: " + this.grandFather2;
text += ", grandmother: " + this.grandMother1;
text += ", grandmother: " + this.grandMother2;
text += ", father: " + this.father;
text += ", mother: " + this.mother;
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;
}
}
}