package com.javarush.task.task08.task0824;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
Human child1 = new Human("sher", true, 27);
Human child2 = new Human("jovo", true, 27);
Human child3 = new Human("Murod", true, 27);
Human father = new Human("Xojixon", true, 55, child1, child2, child3);
Human mother = new Human("Zebo", false, 53, child1, child2, child3);
Human grendfather = new Human("anabibi", false, 85, father, mother);
Human grendfather1 = new Human("anabibi", false, 85, father, mother);
Human grendmother = new Human("Matyoqub", true, 89, father, mother);
Human grendmother1 = new Human("Matyoqub", true, 89, father, mother);
ArrayList<Human> children = new ArrayList<Human>(Arrays.asList(child1, child2, child3, father, mother, grendfather1, grendfather, grendmother1, grendmother));
for(Human h : children){
System.out.println(h);
}
}
public static class Human {
String name;
boolean sex;
int age;
ArrayList<Human> children = new ArrayList<>();
public Human (String name, boolean sex, int age, Human ...children){
this.name = name;
this.sex = sex;
this.age = age;
this.children.addAll(Arrays.asList(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;
}
}
}
Матякубов Шерзод Хожиханович
9 уровень
Help me please !!
Решен
Комментарии (1)
- популярные
- новые
- старые
Для того, чтобы оставить комментарий Вы должны авторизоваться
Игнат
16 июля 2019, 05:40решение
В чем вопрос собственно? У вас по четыре родителя у матери и отца. Первые бабушка и дедушка должны быть родителями отца, вторые - матери.
+4