So when I ran the solution in intellij I literally got the right solution. I put null values for the Human father and Human mother reference which I think may be the issue because I think it may be secretly asking me to reference both constructors(which I don't understand). If that's the case I still don't get the point because I get the right output. Can someone please explain this to me so I can pass this exercise and move on to the next level?
package com.codegym.task.task07.task0724;
/*
Family census
*/
public class Solution {
public static void main(String[] args) {
Human grandFather1 = new Human("Alfonso",true,86,null,null);
Human grandMother1 = new Human("Irma",false,84,null,null);
Human grandFather2 = new Human("David",true,96,null,null);
Human grandMother2 = new Human("Marry",false,94,null,null);
Human father = new Human("Paul",true,60,grandFather2,grandMother2);
Human mother = new Human("Robyn",false,59,grandFather1,grandMother1);
Human child1 = new Human("Christopher",true,26,father,mother);
Human child2 = new Human("Brianna",false,23,father,mother);
Human child3 = new Human("Bunkie",false,12,father,mother);
System.out.println(grandFather1);
System.out.println(grandMother1);
System.out.println(grandFather2);
System.out.println(grandMother2);
System.out.println(father);
System.out.println(mother);
System.out.println(child1);
System.out.println(child2);
System.out.println(child3);
}
public static class Human {
private String name;
private boolean sex;
private int age;
Human father;
Human mother;
public Human(String name, boolean sex, int age){
this.name = name;
this.sex = sex;
this.age = age;
}
public Human(String name, boolean sex, int age, Human father, Human mother){
this.name = name;
this.sex =sex;
this.age = age;
this.father = father;
this.mother = mother;
}
public String toString() {
String text = "";
text += "Name: " + this.name;
text += ", sex: " + (this.sex ? "male" : "female");
text += ", age: " + this.age;
if (this.father != null)
text += ", father: " + this.father.name;
if (this.mother != null)
text += ", mother: " + this.mother.name;
return text;
}
}
}