1
package com.javarush.task.task07.task0724;
/*
Семейная перепись
*/
public class Solution {
public static void main(String[] args) {
Human GrandF = new Human("Dedushka",true,60);
Human GrandM = new Human("Babyshka",false,50);
Human GrandF1 = new Human("Dedushka1",true, 63);
Human GrandM1 = new Human("Babushka1",false, 66);
Human Mother = new Human("Mat'",false,30,GrandF,GrandM);
Human Father = new Human("Otec",true,34,GrandF1,GrandM1);
Human Soon = new Human("Sin",true, 12, Father,Mother);
Human Soon1= new Human("doch",false,8,Father,Mother);
Human Soon2= new Human("sin2",true,2,Father,Mother);
System.out.println(GrandF);
System.out.println(GrandM);
System.out.println(GrandF1);
System.out.println(GrandM1);
System.out.println(Mother);
System.out.println(Father);
System.out.println(Soon);
System.out.println(Soon1);
System.out.println(Soon2);
}
public static class Human {
String name;
boolean sex;
int age;
String father;
String mother;
public Human(){
}
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.name;
this.mother=mother.name;
}
public String toString(Human human)
{
String text = "";
text += "Имя: " + this.name;
text += ", пол: " + (this.sex ? "мужской" : "женский");
text += ", возраст: " + this.age;
if (this.father != null)
text += ", отец: " + this.father;
if (this.mother != null)
text += ", мать: " + this.mother;
return text;
}
}
}