?
package com.codegym.task.task07.task0724;
/*
Family census
*/
public class Solution {
public static void main(String[] args) {
// write your code here
Human grandfather1 = new Human("GrandFather1", true, 70);
Human grandmother1 = new Human("GrandFather1", true, 70);
Human h1 = new Human("GrandFather1",true,23 );
Human h2 = new Human("GrandMother1",false,20);
Human h3 = new Human("GrandFather2",false,12);
Human h4 = new Human("GrandMother2",true, 42);
Human h5 = new Human("Father", true , 12, h1,h2);
Human h6 = new Human("Mother", false , 12, h3, h4);
Human h7 = new Human("children1", false , 12, h5,h6);
Human h8 = new Human("children2", true , 12, h5, h6);
Human h9 = new Human("children3", false , 12,h5,h6);
System.out.println(h1.toString());
System.out.println(h2.toString());
System.out.println(h3.toString());
System.out.println(h4.toString());
System.out.println(h5.toString());
System.out.println(h6.toString());
System.out.println(h7.toString());
System.out.println(h8.toString());
System.out.println(h9.toString());
}
public static class Human {
// write your code here
private String name;
private boolean sex;
private int age;
private Human father;
private Human mother;
Human(String name, boolean sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
}
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 += "Name: " + this.name;
text += ", sex: " + (this.sex ? "male" : "female");
text += ", age: " + this.age;
if (this.father != null)
text += ", father: " + this.father.name;
if (this.mother != null)
text += ", mother: " + this.mother.name;
return text;
}
}
}