??
package com.javarush.task.task07.task0724;
/*
Семейная перепись
*/
public class Solution {
public static void main(String[] args) {
Human grandf1 = new Human("ghj", 12, true);
Human grandf2 = new Human("ghj", 12, true);
Human grandm2 = new Human("ghj", 12, true);
Human grandm1 = new Human("ghj", 12, true);
Human kid1 = new Human("ghj", 12, true, grandf1, grandm1);
Human kid2 = new Human("ghj", 12, true, grandf1, grandm1);
Human kid3 = new Human("ghj", 12, true, grandf1, grandm1);
Human mother = new Human("ghj", 12, true, grandf2, grandm2);
Human father = new Human("ghj", 12, true, grandf1, grandm1);
System.out.println(grandf1.toString());
System.out.println(grandf2.toString());
System.out.println(grandm1.toString());
System.out.println(grandm2.toString());
System.out.println(kid1.toString());
System.out.println(kid2.toString());
System.out.println(kid3.toString());
System.out.println(mother.toString());
System.out.println(father.toString());
}
public static class Human {
String name;
int age;
boolean sex;
Human father;
Human mother;
public Human(String name, int age, boolean sex) {
this.name = name;
this.age = age;
this.sex = sex;
}
public Human(String name, int age, boolean sex, Human father, Human mother) {
this.name = name;
this.age = age;
this.sex = sex;
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;
}
}
}