public class Solution {
public static void main(String[] args) {
Human grandmother1 = new Human("Маша", false,70, mother);
Human grandmother2 = new Human("Вика", false,80, father);
Human grandfather1 = new Human("Саша", true, 90, mother);
Human grandfather2 = new Human("Петя", true, 100, father);
Human mother = new Human("Валя", false, 45, children);
Hunan father = new Human("Женя", true, 45, children);
ArrayList<Human> children = new ArrayList<Human>();
children.add(new Human("Соня", false, 20));
children.add(new Human("Федор", true, 20));
children.add(new Human("Вася", true, 20));
System.out.println(text);
}
public class Human {
String name;
boolean sex;
int age;
ArrayList<Human> children;
public Human (String name; boolean sex; int age; ArrayList<Human> children){
this.name = name;
this.sex = sex;
this.age = age;
this.children = new ArrayList<Human>();
}
public Human (String name; boolean sex; int age) {
this.name = name;
this.sex = sex;
this.age = age;
}
}
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
public class Solution {
public static void main(String[] args) {
Human grandmother1 = new Human("Маша", false,70, mother);
Human grandmother2 = new Human("Вика", false,80, father);
Human grandfather1 = new Human("Саша", true, 90, mother);
Human grandfather2 = new Human("Петя", true, 100, father);
Human mother = new Human("Валя", false, 45, children);
Hunan father = new Human("Женя", true, 45, children);
ArrayList<Human> children = new ArrayList<Human>();
children.add(new Human("Соня", false, 20));
children.add(new Human("Федор", true, 20));
children.add(new Human("Вася", true, 20));
System.out.println(text);
}
public class Human {
String name;
boolean sex;
int age;
ArrayList<Human> children;
public Human (String name; boolean sex; int age; ArrayList<Human> children){
this.name = name;
this.sex = sex;
this.age = age;
this.children = new ArrayList<Human>();
}
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;
}
}
}