Не вижу, где ошибка
package com.javarush.task.task07.task0724;
/*
Семейная перепись
*/
public class Solution {
public static void main(String[] args) {
Human grandFather0 = new Human("Pavel", true, 68, null, null );
Human grandFather1 = new Human("Valera", true, 72, null, null );
Human grandMother0 = new Human("Luda", false, 64, null, null );
Human grandMother1 = new Human("Zina", false, 67, null, null );
Human father = new Human("Gena", true, 40, grandFather0, grandMother0);
Human mother = new Human("Olya", false, 35, grandFather1, grandMother1);
Human son0 = new Human("Petya", true, 10, father, mother);
Human son1 = new Human("Vasya", true, 12, father, mother);
Human daughter = new Human("Sofia", false, 7, father, mother);
}
public static class Human {
private String name;
private boolean sex;
private int age;
private Human father;
private Human mother;
public Human(String name, boolean sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
System.out.println(toString());
}
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;
System.out.println(toString());
}
public String toString() {
String text = "";
text += "Имя: " + this.name;
text += ", пол: " + (this.sex ? "мужской" : "женский");
text += ", возраст: " + this.age;
if (this.father != null) {
text += ", отец: " + this.father.name;
}
if (this.mother != null) {
text += ", мать: " + this.mother.name;
}
return text;
}
}
}