Кто объяснит?
package com.javarush.task.task07.task0724;
/*
Семейная перепись
*/
import java.util.*;
public class Solution {
public static ArrayList<Human>list=new ArrayList<>() ;
public static void main(String[] args) {
// напишите тут ваш код
Human gma=new Human ( "name", true, 6) ;
Human gma1=new Human (" name", true, 6) ;
Human gfa=new Human ("name", false, 6) ;
Human gfa1=new Human ( "name", false, 6) ;
Human child2a=new Human( "name", true, 6, father , mother ) ;
Human child2b=new Human( "name", true, 6, father, mother ) ;
Human child2c=new Human("name", false, 5, father, mother) ;
Human child2d=new Human("name", false, 5, father, mother) ;
Human child2e=new Human( "name", false, 5, father, mother ) ;
for(Human i: list)
System.out.println(i);
}
public static class Human {
// напишите тут ваш код
String name;
boolean sex;
int age;
Human father;
Human mother;
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, Human father, Human mother) {
this.name=name;
this.sex=sex;
this.age=age;
this.father=father;
this.mother=mother;
}
public String toString() {
String text = "";
text += "Имя: " + this.name;
text += ", пол: " + (this.sex ? "мужской" : "женский");
text += ", возраст: " + this.age;
if (this.father != null) {
text += ", отец: " + this.father.name;
}
if (this.mother != null) {
text += ", мать: " + this.mother.name;
}
return text;
}
}
}