Вывод у программы правильный, но валидацию не проходит
package com.javarush.task.task07.task0724;
/*
Семейная перепись
*/
public class Solution {
public static void main(String[] args) {
Human grandFatherFather = new Human("Дедушка по папе", true, 75);
Human grandMotherFather = new Human("Бабушка по папе", false, 70);
Human grandFatherMother = new Human("Дедушка по маме", true, 69);
Human grandMotherMother = new Human("Бабеушка по маме", false, 65);
Human father = new Human("Папа",true, 42, grandFatherFather, grandMotherFather );
Human mother = new Human("Мама", false, 41, grandFatherMother,grandMotherMother);
Human child1 = new Human("1-й ребёнок", true, 14, father, mother);
Human child2 = new Human("2-й ребёнок", false, 12, father, mother);
Human child3 = new Human("3-й ребёнок", true, 7, father, mother);
System.out.println(grandFatherFather);
System.out.println(grandMotherFather);
System.out.println(grandFatherMother);
System.out.println(grandMotherMother);
System.out.println(father);
System.out.println(mother);
System.out.println(child1);
System.out.println(child2);
System.out.println(child3);
//напишите тут ваш код
}
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;
}
}
}