совсем протек и уже наверное над все затирать и заного писать ))) мозг рехнулся(((
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
import java.util.ArrayList;
import java.util.Arrays;
public class Solution {
public static void main(String[] args) {
ArrayList<String> Childrens = new ArrayList<>();
Childrens.add("Вова");
Childrens.add("Петя");
Childrens.add("Костя");
Human child = new Human("Вова", true, 10);
Human child2 = new Human("Петя", true, 10);
Human child3 = new Human("Костя",true ,10);
Human mama = new Human("МамаКатя", false,30,new ArrayList<Human>(Arrays.asList(child,child2,child3)));
Human papa = new Human("ПапаДима",true,30,new ArrayList<Human>(Arrays.asList(child,child2,child3)));
Human dedaPapi = new Human("ДедаАльберт",true,56,new ArrayList<Human>(Arrays.asList(papa)));
Human babaPapi = new Human("БабаНика",false,56,new ArrayList<Human>(Arrays.asList(papa)));
Human dedaMami = new Human("ДедаСемён",true,56,new ArrayList<Human>(Arrays.asList(mama)));
Human babaMami = new Human("БабаКлише",false,56,new ArrayList<Human>(Arrays.asList(mama)));
}
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;
System.out.println(this.toString());
}
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;
}
}
}