Все создает, все выводит, чего ему не нравиться (
package com.javarush.task.task08.task0824;
import sun.security.krb5.internal.crypto.HmacMd5ArcFourCksumType;
import java.util.ArrayList;
import java.util.List;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
Human child1 = new Human("Ko", true, 3);
Human child2 = new Human("Zo", false, 6);
Human child3 = new Human("Mo", true, 9);
ArrayList<Human> child = new ArrayList<>();
child.add(child1);
child.add(child2);
child.add(child3);
Human father = new Human("Bob", true, 36, child);
Human mother = new Human("Mom", false, 34, child);
ArrayList<Human> fatherA = new ArrayList<>();
fatherA.add(father);
ArrayList<Human> motherA = new ArrayList<>();
motherA.add(mother);
Human grandPa = new Human("Nobo", true, 51, fatherA);
Human grandPa2 = new Human("Fobo", true, 54);
Human grandMa = new Human("Lolo", false, 50, motherA);
Human grandMa2 = new Human("Fifa", false, 49);
System.out.println(grandPa);
System.out.println(grandPa2);
System.out.println(grandMa);
System.out.println(grandMa2);
System.out.println(father);
System.out.println(mother);
for (Human human : child) {
System.out.println(human);
}
}
public static class Human {
//напишите тут ваш код
String name;
Boolean sex;
int age;
ArrayList<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, ArrayList<Human> child) {
this.name = name;
this.sex = sex;
this.age = age;
this.children = child;
}
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;
}
}
}