Третий день решаю, не могу решить. Вроде поняла логику задачи, а вроде не совсем. Запуталась.
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.List;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
Human kid1 = new Human("z", true, 10);
Human kid2 = new Human("x", true, 9);
Human kid3 = new Human("c", true, 8);
ArrayList<Human> children = new ArrayList<>();
//children.add(kid1);
//children.add(kid2);
//children.add(kid3);
Human man1 = new Human("A", true, 25, children);
Human man2 = new Human("B", false, 24, children);
ArrayList<Human> child1 = new ArrayList<>();
//child1.add(man1);
ArrayList<Human> child2 = new ArrayList<>();
//child2.add(man2);
Human human1 = new Human("Q", true, 50, child1);
Human human2 = new Human("W", false, 49, child1);
Human human3 = new Human("E", true, 48, child2);
Human human4 = new Human("R", false, 47, child2);
System.out.println(kid1);
System.out.println(kid2);
System.out.println(kid3);
System.out.println(man1);
System.out.println(man2);
System.out.println(human1);
System.out.println(human2);
System.out.println(human3);
System.out.println(human4);
}
public static class Human {
//напишите тут ваш код
String name;
boolean sex;
int age;
ArrayList<Human> children;
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, ArrayList<Human> children) {
this.name = name;
this.sex = sex;
this.age = age;
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;
}
}
}