Выдача норм условия выполнены
package com.javarush.task.task07.task0724;
/*
Семейная перепись
*/
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
Human gFather1 = new Human("Дед1", 50, true);
Human gMather1 = new Human("Баба1", 45, false);
Human gFather2 = new Human("Дед2", 50, true);
Human gMather2 = new Human("Баба1", 45, false);
Human father = new Human("Отец", 55, true, gFather2, gMather2);
Human mather = new Human("Мать", 45, false, gFather1, gMather1);
Human san = new Human("Сын", 20, true, father, mather);
Human dota = new Human("Доч", 18, false, father, mather);
System.out.println(gFather1);
System.out.println(gMather1);
System.out.println(gFather2);
System.out.println(gMather2);
System.out.println(father);
System.out.println(mather);
System.out.println(san);
System.out.println(dota);
}
public static class Human {
//напишите тут ваш код
String name;
int age;
boolean sex;
Human father;
Human mother;
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 Human(String name, int age, boolean sex) {
this.name = name;
this.age = age;
this.sex = sex;
}
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;
}
}
}