?
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
Human Grandfather = new Human("Никита",true,67);
Human Grandfather2 = new Human("Егор",true,68);
Human Grandmother = new Human("Анна",false,66);
Human Grandmother2 = new Human("Криcтина",false,64);
Human father = new Human("Олег",true,44,son1);
Human mother = new Human("Настя",false,42,daughter);
Human son1 = new Human("Семен",true,18);
Human son2 = new Human("Алексей",true,20);
Human daughter = new Human("Алена",false,21);
System.out.println(Grandfather.toString());
System.out.println(Grandfather2.toString());
System.out.println(Grandmother.toString());
System.out.println(Grandmother2.toString());
System.out.println(father.toString());
System.out.println(mother.toString());
System.out.println(son1.toString());
System.out.println(son2.toString());
System.out.println(daughter.toString());
List<Human> children = new ArrayList<>();
children.add(son1);
children.add(son2);
children.add(daughter);//напишите тут ваш код
}
public static class Human {
String name;
boolean sex;
int age;
List<Human> children = new ArrayList<>();
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 children) {
this.name = name;
this.sex = sex;
this.age = age;
Collections.addAll(this.children, children);
}
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;
}
}
}