Hello, as in the topic - the program seems to work but the verifier doesn't want to let it go :( It is probably a small mistake that I can't (yet) see ^^"
any help appreciate ;3
package com.codegym.task.task08.task0824;
/*
Requirements:
1. The program should display text on the screen.
2. The Human class must have four fields.
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.
String name, boolean sex, int age, and ArrayList<Human> children fields.
*/
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
Human grandfather1= new Human(true, 98, "George", new ArrayList<Human>());
Human grandfather2 = new Human(true, 101, "Martin", new ArrayList<Human>());
Human grandmother1 = new Human(false, 99, "Martina", new ArrayList<Human>());
Human grandmother2 = new Human(false, 100, "Anna", new ArrayList<Human>());
Human mother= new Human(false, 67, "Manna", new ArrayList<Human>());
Human father = new Human(true, 70, "Arron", new ArrayList<Human>());
Human child1 = new Human(false, 37, "Anita", new ArrayList<Human>());
Human child2 = new Human(true, 44, "Andrew", new ArrayList<Human>());
Human child3 = new Human(false, 38, "Monica", new ArrayList<Human>());
ArrayList<Human> children = new ArrayList<Human>();
father.children.add(child1);
father.children.add(child2);
father.children.add(child3);
mother.children.add(child1);
mother.children.add(child2);
mother.children.add(child3);
grandfather1.children.add(mother);
grandfather2.children.add(mother);
grandfather1.children.add(father);
grandfather2.children.add(father);
grandmother1.children.add(mother);
grandmother2.children.add(mother);
grandmother1.children.add(father);
grandmother2.children.add(father);
System.out.println(grandfather1.toString());
System.out.println(grandfather2.toString());
System.out.println(grandmother1.toString());
System.out.println(grandmother2.toString());
System.out.println(mother.toString());
System.out.println(father.toString());
System.out.println(child1.toString());
System.out.println(child2.toString());
System.out.println(child3.toString());
for (Human child : children) {
System.out.println(child);}
}
public static class Human {
boolean sex;
int age;
String name;
ArrayList<Human> children;
public Human(boolean sex, int age, String name, ArrayList<Human> children) {
this.name = name;
this.age = age;
this.sex = sex;
this.children = children;
}
public Human(boolean sex, int age, String name) {
this.name = name;
this.age = age;
this.sex = sex;
}
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;
}
}
}