Π― ΠΏΠΎΠ½ΠΈΠΌΠ°Ρ, ΡΡΠΎ Π½ΡΠΆΠ½ΠΎ ΡΠΎΠ·Π΄Π°ΡΡ ΠΊΠΎΠ½ΡΡΡΡΠΊΡΠΎΡΡ. ΠΠΎ Ρ
ΠΎΡΡ ΡΠ±Π΅ΠΉ, Π½Π΅ ΠΌΠΎΠ³Ρ ΠΏΠΎΠ½ΡΡΡ, ΠΊΠ°ΠΊ Π·Π°Π»ΠΎΠΆΠΈΡΡ Π² ΠΊΠΎΠ½ΡΡΡΡΠΊΡΠΎΡ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΡ Π΄Π΅ΡΠ΅ΠΉ, Π΄Π° Π΅ΡΠ΅ ΡΠΏΠΈΡΠΊΠΎΠΌ... ΠΡΡΡ Π³Π΄Π΅-Π½ΠΈΠ±ΡΠ΄Ρ ΠΏΠΎΡΡΠ°ΠΏΠ½ΠΎΠ΅ ΠΎΠΏΠΈΡΠ°Π½ΠΈΠ΅ ΡΠ΅ΡΠ΅Π½ΠΈΡ ΡΡΠΎΠΉ Π·Π°Π΄Π°ΡΠΈ Π΄Π»Ρ ΠΏΠΎΠ»Π½ΡΡ
Π΄Π΅Π±ΠΈΠ»ΠΎΠ²? Π― ΡΠΆΠ΅ 2 ΠΏΠΎΠ΄ΠΎΠ±Π½ΡΡ
Π·Π°Π΄Π°ΡΠΈ ΠΏΡΠΎΠΏΡΡΡΠΈΠ» ΠΈ ΡΡΠΎ-ΡΠΎ ΠΏΠΎΠ΄ΡΠΊΠ°Π·ΡΠ²Π°Π΅Ρ, ΡΡΠΎ Π΄Π°Π»ΡΡΠ΅ ΡΡΠΈ ΠΏΡΠΎΠ±Π΅Π»Ρ ΠΌΠ½Π΅ Π°ΡΠΊΠ½ΡΡΡΡ.
ΠΠ° ΠΏΠ΅ΡΠ²ΠΎΠΌ Π°ΠΊΠΊΠ°ΡΠ½ΡΠ΅ Π΄ΠΎΡΠ΅Π» Π΄ΠΎ 8 ΡΡΠΎΠ²Π½Ρ. ΠΠ° Π²ΡΠΎΡΠΎΠΌ - Π΄ΠΎ 16-Π³ΠΎ... ΠΡΠΎ ΡΡΠ΅ΡΡΡ ΠΏΠΎΠΏΡΡΠΊΠ°.
package com.javarush.task.task08.task0824;
/*
Π‘ΠΎΠ±ΠΈΡΠ°Π΅ΠΌ ΡΠ΅ΠΌΠ΅ΠΉΡΡΠ²ΠΎ
*/
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
Human hum1 = new Human("ΠΠ°ΡΡ", true, 80);
Human hum2 = new Human("ΠΠ΅ΡΡ", true, 80);
Human hum3 = new Human("ΠΠ°Π»Ρ", true, 80);
Human hum4 = new Human("ΠΠ°Π΄Ρ", true, 80);
}
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;
}
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;
}
}
}