есть все кроме детей
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.List;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
Human child1 = new Human("child1", false,3,null);
Human child2 = new Human("child2", false, 5,null);
Human child3 = new Human("child3", false, 15,null);
Human father = new Human("father", true, 30, child1,child2,child3);
Human morher = new Human("mather", false, 30, child1,child2,child3);
Human ded1 = new Human("ded1", true, 60, father);
Human ded2 = new Human("ded2", true, 60, morher);
Human baba1 = new Human("baba1", false, 60, morher);
Human baba2 = new Human("baba2", false, 60, father);
System.out.println(ded1.toString());
System.out.println(ded2.toString());
System.out.println(baba1.toString());
System.out.println(baba2.toString());
System.out.println(father.toString());
System.out.println(morher.toString());
System.out.println(child1.toString());
System.out.println(child2.toString());
System.out.println(child3.toString());
}
public static class Human {
String name;
boolean sex;
int age;
ArrayList<Human> children;
public Human(String name, boolean sex, int age, Human human1,Human human2,Human human3) {
this.name = name;
this.age = age;
this.sex = sex;
children = new ArrayList<>();
children.add(human1);
children.add(human2);
children.add(human3);
}
public Human(String name, boolean sex, int age, Human human) {
this.name = name;
this.age = age;
this.sex = sex;
children = new ArrayList<>();
children.add(human);
}
public Human(String name, boolean sex, int age) {
this.name = name;
this.age = age;
this.sex = sex;
}
public String toString() {
String text = "";
text += "Имя: " + this.name;
text += ", пол: " + (this.sex ? "мужской" : "женский");
text += ", возраст: " + this.age;
int childCount = this.children.size();
if (childCount > 0) {
text += ", дети: " + this.children.get(0).name;
for (int i = 1; i < childCount; i++) {
Human child = this.children.get(i);
text += ", " + child.name;
}
}
return text;
}
}
}