Все условия выполнены.
Объекты загоняю в ArrayList, чтобы потом вывести форичем, а не руками.
Из второго конструктора вызываю первый, опять же аккуратней и не руками.
Все переменные и конструкторы на которые ругается валидатор присутствуют.
Код выполняется корректно
package com.javarush.task.task07.task0724;
/*
Семейная перепись
*/
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
// напишите тут ваш код
ArrayList<Human> humans = new ArrayList<Human>();
//деды
humans.add(new Human("Аня", false, 60));//0
humans.add(new Human("Маша", false, 70));//1
humans.add(new Human("Вася", true, 51));//2
humans.add(new Human("Петя", true, 61));//3
//родители
humans.add(new Human("Катя", false, 61, humans.get(3), humans.get(1)));//4 moth
humans.add(new Human("Макар", true, 41, humans.get(2), humans.get(0)));//5 fath
//дети
humans.add(new Human("Нина", false, 20, humans.get(5), humans.get(4)));//4
humans.add(new Human("Лена", false, 40, humans.get(5), humans.get(4)));//5
humans.add(new Human("Леша", true, 51, humans.get(5), humans.get(4)));//8
for (Human x: humans) {
System.out.println(x);
}
}
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;
}
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;
}
}
}