Подскажите, в чем может быть проблема?
Особенно не ясно условие - "Класс Human должен содержать один метод" а на старте класс Human уже содержит два метода: main и toString
package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.List;
/*
Собираем семейство
*/
public class Solution {
public static class Human {
public String name;
public boolean sex;
public int age;
public List<Human> children = new ArrayList<>();
public static void main(String[] args) {
//напишите тут ваш код
Human child1 = new Human("child 1", true, 10);
Human child2 = new Human("child 2", true, 11);
Human child3 = new Human("child 3", true, 12);
List<Human> children = new ArrayList<>();
List<Human> fatherList = new ArrayList<>();
List<Human> motherList = new ArrayList<>();
children.add(child1);
children.add(child2);
children.add(child3);
Human father = new Human("father",true, 40,children);
Human mother = new Human("mother",false, 38,children);
fatherList.add(father);
motherList.add(mother);
Human grandFa1 = new Human("grand father 1", true,70,fatherList );
Human grandFa2 = new Human("grand father 2", true,71, motherList);
Human grandMa1 = new Human("grand mother 1", false,72, fatherList);
Human grandMa2 = new Human("grand mother 2", false,73, motherList);
System.out.println(child1.toString());
System.out.println(child2.toString());
System.out.println(child3.toString());
System.out.println(father.toString());
System.out.println(mother.toString());
System.out.println(grandFa1.toString());
System.out.println(grandFa2.toString());
System.out.println(grandMa1.toString());
System.out.println(grandMa2.toString());
}
//напишите тут ваш код
public Human(String name, boolean sex, int age,List<Human> children){
this.name = name;
this.sex = sex;
this.age = age;
this.children = children;
}
public Human(String name, boolean sex, int age){
this.name = name;
this.sex = sex;
this.age = age;
}
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;
}
}
}