при запуске на исполнение выводит:
Имя: Meina, пол: женский, возраст: 1, отец: Meina, мать: Meina
Имя: Meina, пол: женский, возраст: 1, отец: Meina, мать: Meina
Имя: Meina, пол: женский, возраст: 1, отец: Meina, мать: Meina
Имя: Meina, пол: женский, возраст: 1, отец: Meina, мать: Meina
Имя: Meina, пол: женский, возраст: 1, отец: Meina, мать: Meina
Имя: Meina, пол: женский, возраст: 1, отец: Meina, мать: Meina
Имя: Meina, пол: женский, возраст: 1, отец: Meina, мать: Meina
Имя: Meina, пол: женский, возраст: 1, отец: Meina, мать: Meina
Имя: Meina, пол: женский, возраст: 1, отец: Meina, мать: Meina
package com.javarush.task.task07.task0724;
/*
Семейная перепись
*/
public class Solution {
public static void main(String[] args) {
Human grandFatherJon = new Human("Jon",true,55);
Human grandFatherNeck = new Human("Neck",true,52);
Human grandMotherJule = new Human( "Juli",false,55);
Human grandMotherRima = new Human( "Rima",false,48);
Human fatherKirk = new Human("Kirk",true,32,grandFatherJon,grandMotherJule);
Human motherKlara = new Human("Klara",false,25,grandFatherNeck,grandMotherRima);
Human sonBill = new Human("Bill",true,7,fatherKirk,motherKlara);
Human sonRoss = new Human("Ross",true,5,fatherKirk,motherKlara);
Human daughterMeina = new Human("Meina",false,1,fatherKirk,motherKlara);
System.out.println(grandFatherJon.toString());
System.out.println(grandFatherNeck.toString());
System.out.println(grandMotherJule.toString());
System.out.println(grandMotherRima.toString());
System.out.println(fatherKirk.toString());
System.out.println(motherKlara.toString());
System.out.println(sonBill.toString());
System.out.println(sonRoss.toString());
System.out.println(daughterMeina.toString());
}
public static class Human {
public static String name;
public static boolean sex;
public static int age;
public static Human father;
public static 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,sex,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;
}
}
}