Вообщем,ошибка тут
if (this.fa != null) {
text += ", отец: " + this.fa.name;
}
Что то очевидное,Но я с утра как то щас слабоват,тыкните пальцем))package com.javarush.task.task07.task0724;
/*
Семейная перепись
*/
public class Solution {
public static void main(String[] args) {
Human grandMa1 = new Human("бабка 1",false,51,null,null);
Human grandMa2 = new Human("бабка 2",false,52,null,null);
Human grandFa1 = new Human("батька 1",true,51,null,null);
Human grandFa2 = new Human("батька 2",true,52,null,null);
Human mother = new Human("мамка",false,30,grandFa1.name,grandMa1.name);
Human father = new Human("папка",true,30,grandFa2.name,grandMa2.name);
Human kid1 = new Human("чадо1",true,11,father.name,mother.name);
Human kid2 = new Human("чадо2",true,12,father.name,mother.name);
Human kid3 = new Human("чадо3",true,13,father.name,mother.name);
}
public static class Human {
String name;
boolean sex;
int age;
String ma;
String fa;
public Human(String name,boolean sex,int age,String fa,String ma){
this.name=name;
this.sex=sex;;
this.age=age;
this.fa=fa;
this.ma=ma;
}
public String toString() {
String text = "";
text += "Имя: " + this.name;
text += ", пол: " + (this.sex ? "мужской" : "женский");
text += ", возраст: " + this.age;
if (this.fa != null) {
text += ", отец: " + this.fa.name;
}
if (this.ma != null) {
text += ", мать: " + this.ma.name;
}
return text;
}
}
}