public static void main(String[] args) {
//напишите тут ваш код
//Создание объектов детей
Human child1 = new Human("Саша", true, 19);
Human child2 = new Human("Даша", false, 15);
Human child3 = new Human("Маша", false, 8);
Human child4 = new Human("Гоша", true, 19);
Human child5 = new Human("Света", false, 15);
Human child6 = new Human("Лада", false, 8);
//Создание списка детей
ArrayList<Human> childrenJr = new ArrayList<>();
ArrayList<Human> childrenJr2 = new ArrayList<>();
//Добавление детей в список
//Добавление детей в список
childrenJr.add(child1);
childrenJr.add(child2);
childrenJr.add(child3);
childrenJr2.add(child4);
childrenJr2.add(child5);
childrenJr2.add(child6);
//Создание объектов родителей
Human father = new Human("Михаил", true, 45, childrenJr);
Human mather = new Human("Ирина", false,42, childrenJr);
Human father2 = new Human("Николай", true, 45, childrenJr2);
Human mather2 = new Human("Марина", false,42, childrenJr2);
//Создание списка родителям
ArrayList<Human> childrenOlder = new ArrayList<>();
childrenOlder.add(father);
childrenOlder.add(mather);
ArrayList<Human> childrenOlder2 = new ArrayList<>();
childrenOlder2.add(father2);
childrenOlder2.add(mather2);
Human grabdFather1 = new Human("Дед Вася", true, 92, childrenOlder);
Human grandMather1 = new Human("Баба Настя", false, 89, childrenOlder);
Human grabdFather2 = new Human("Дед Юра", true, 87, childrenOlder2);
Human grandMather2 = new Human("Баба Галя", false, 85, childrenOlder2);
System.out.println(grabdFather1.toString());
System.out.println(grabdFather2.toString());
package com.javarush.task.task08.task0824;
import java.util.*;
import java.util.ArrayList;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
//Создание объектов детей
Human child1 = new Human("Саша", true, 19);
Human child2 = new Human("Даша", false, 15);
Human child3 = new Human("Маша", false, 8);
Human child4 = new Human("Гоша", true, 19);
Human child5 = new Human("Света", false, 15);
Human child6 = new Human("Лада", false, 8);
//Создание списка детей
ArrayList<Human> childrenJr = new ArrayList<>();
ArrayList<Human> childrenJr2 = new ArrayList<>();
//Добавление детей в список
//Добавление детей в список
childrenJr.add(child1);
childrenJr.add(child2);
childrenJr.add(child3);
childrenJr2.add(child4);
childrenJr2.add(child5);
childrenJr2.add(child6);
//Создание объектов родителей
Human father = new Human("Михаил", true, 45, childrenJr);
Human mather = new Human("Ирина", false,42, childrenJr);
Human father2 = new Human("Николай", true, 45, childrenJr2);
Human mather2 = new Human("Марина", false,42, childrenJr2);
//Создание списка родителям
ArrayList<Human> childrenOlder = new ArrayList<>();
childrenOlder.add(father);
childrenOlder.add(mather);
ArrayList<Human> childrenOlder2 = new ArrayList<>();
childrenOlder2.add(father2);
childrenOlder2.add(mather2);
Human grabdFather1 = new Human("Дед Вася", true, 92, childrenOlder);
Human grandMather1 = new Human("Баба Настя", false, 89, childrenOlder);
Human grabdFather2 = new Human("Дед Юра", true, 87, childrenOlder2);
Human grandMather2 = new Human("Баба Галя", false, 85, childrenOlder2);
System.out.println(grabdFather1.toString());
System.out.println(grabdFather2.toString());
System.out.println(grandMather1.toString());
System.out.println(grandMather2.toString());
System.out.println(father.toString());
System.out.println(mather.toString());
System.out.println(father2.toString());
System.out.println(mather2.toString());
System.out.println(child1.toString());
System.out.println(child2.toString());
System.out.println(child3.toString());
System.out.println(child4.toString());
System.out.println(child5.toString());
System.out.println(child6.toString());
}
public static class Human {
//напишите тут ваш код
String name;
int age;
boolean sex;
//ArrayList<Human> father = new ArrayList<>();
ArrayList<Human> children = new ArrayList<>();
Human(String name,boolean sex,int age,ArrayList<Human> children) {
this.name = name;
this.sex = sex;
this.age = age;
this.children = children;
}
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;
}
}
}