В консоль выводиться верный ответ.
package com.javarush.task.jdk13.task07.task0724;
public class Solution {
public static void main(String[] args) {
Human maternalGrandmother = new Human("Мария", false, 60);
Human maternalGrandfather = new Human("Александр", true, 63);
Human paternalGrandmother = new Human("Ольга", false, 62);
Human paternalGrandfather = new Human("Петр", true, 61);
Human mother = new Human("Елена", false, 30, maternalGrandmother, maternalGrandfather);
Human father = new Human("Андрей", true, 35, paternalGrandmother, paternalGrandfather);
Human firstChild = new Human("Виктор", true, 5, mother, father);
Human secondChild = new Human("Игорь", true, 15, mother, father);
Human thirdChild = new Human("Сергей", false, 10, mother, father);
System.out.println(maternalGrandfather);
System.out.println(maternalGrandmother);
System.out.println(paternalGrandfather);
System.out.println(paternalGrandmother);
System.out.println(mother);
System.out.println(father);
System.out.println(firstChild);
System.out.println(secondChild);
System.out.println(thirdChild);
}
}
class Human {
String name;
boolean sex;
int age;
Human mother;
Human father;
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 mother,Human father) {
this.name = name;
this.sex = sex;
this.age = age;
this.mother = mother;
this.father = father;
}
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;
}
}