Всем привет. Не могу найти ошибку, в консоль выводит всё в соответствии с заданием.
package com.javarush.task.task07.task0724;
/*
Семейная перепись
*/
public class Solution {
public static void main(String[] args) {
// напишите тут ваш код
Human ded = new Human("Женя", true, 78, null, null);
Human ded1 = new Human("Ггриша", true, 81, null, null);
Human babka = new Human("Галя", false, 65, null, null);
Human babka1 = new Human("Валя", false, 68, null, null);
Human father = new Human("Саша", true, 45, ded, babka);
Human mother = new Human("Клава", false, 42, ded1, babka1);
Human son1 = new Human("петя", true, 15, father, mother);
Human son2 = new Human("коля", true, 11, father, mother);
Human son3 = new Human("вова", true, 12, father, mother);
System.out.println(ded);
System.out.println(ded1);
System.out.println(babka);
System.out.println(babka1);
System.out.println(father);
System.out.println(mother);
System.out.println(son1);
System.out.println(son2);
System.out.println(son3);
}
public static class Human {
// напишите тут ваш код
String name;
boolean sex;
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 += "Имя: " + 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;
}
}
}