??
package com.javarush.task.task07.task0724;
/*
Семейная перепись
*/
import java.util.ArrayList;
public class Solution {
public static ArrayList<Human> list = new ArrayList<>();
public static void main(String[] args) {
Human dedushka = new Human("Armen", true, 45 );
Human dedushka1 = new Human("Arme", true, 40 );
Human babushka = new Human("Arm", false, 15 );
Human babushka1 = new Human("Ar", false, 48 );
Human father = new Human("mush", true, 45 , dedushka, babushka);
Human mother = new Human("kekas", false, 40 , dedushka1, babushka1);
Human child1 = new Human("piso", true, 15 , father, mother);
Human child2 = new Human("brat", false, 48, father, mother );
Human child3 = new Human("drug", false, 48, father, mother );
for(Human s : list)
System.out.println(s);
}
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;
list.add(Human.this);
}
public Human(String name, boolean sex, int age, Human father, Human mother){
this.name = name;
this.sex = sex;
this.age = age;
this.father.name = father.name;
this.mother.name = mother.name;
list.add(Human.this);
}
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;
}
}
}