.
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) {
Solution.Human child1 = new Solution.Human();
child1.name = "Mike";
child1.sex = true;
child1.age = 3;
Solution.Human child2 = new Solution.Human();
child2.name = "Alina";
child2.sex = false;
child2.age = 13;
Solution.Human child3 = new Solution.Human();
child3.name = "John";
child3.sex = true;
child3.age = 23;
Solution.Human grandmother1 = new Solution.Human();
grandmother1.name = "Jess";
grandmother1.sex = false;
grandmother1.age = 84;
Solution.Human grandmother2 = new Solution.Human();
grandmother2.name = "Mia";
grandmother2.sex = false;
grandmother2.age = 94;
Solution.Human grandfather1 = new Solution.Human();
grandfather1.name = "Jake";
grandfather1.sex = true;
grandfather1.age = 38;
Solution.Human grandfather2 = new Solution.Human();
grandfather2.name = "Fin";
grandfather2.sex = true;
grandfather2.age = 39;
Solution.Human father = new Solution.Human();
father.name = "Salavat";
father.sex = true;
father.age = 43;
father.children.add(child1);
father.children.add(child2);
father.children.add(child3);
Solution.Human mother = new Solution.Human();
mother.name = "Emiliya";
mother.sex = false;
mother.age = 93;
mother.children.add(child1);
mother.children.add(child2);
mother.children.add(child3);
System.out.println(grandfather1.toString());
System.out.println(grandfather2.toString());
System.out.println(grandmother1.toString());
System.out.println(grandmother2.toString());
System.out.println(mother.toString());
System.out.println(father.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 = new ArrayList<>();
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;
}
}
}