package com.codegym.task.task07.task0724;
/*
Family census
*/
public class Solution {
public static void main(String[] args) {
Human h1 = new Human("Joseph",true,70);
Human h2 = new Human("Mary",false,65);
Human h3 = new Human("Phillips",true,65);
Human h4 = new Human("Julie",false,60);
Human h5 = new Human("Robert",true,40,h1,h2);
Human h6 = new Human("Elizabeth",false,35,h3,h4 );
Human h7 = new Human("Rita",false,10,h5,h6 );
Human h8 = new Human("James",true,7,h5,h6 );
Human h9 = new Human("Theresa",false,3,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());
// write your code here
}
public static class Human {
String name;
boolean sex;
int age;
static Human father;
static 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;
Human.father = father;
Human.mother = mother;}
// write your code here
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;
}
}
}
package com.codegym.task.task07.task0724;
/*
Family census
*/
public class Solution {
public static void main(String[] args) {
Human h1 = new Human("Joseph",true,70);
Human h2 = new Human("Mary",false,65);
Human h3 = new Human("Phillips",true,65);
Human h4 = new Human("Julie",false,60);
Human h5 = new Human("Robert",true,40,h1,h2);
Human h6 = new Human("Elizabeth",false,35,h3,h4 );
Human h7 = new Human("Rita",false,10,h5,h6 );
Human h8 = new Human("James",true,7,h5,h6 );
Human h9 = new Human("Theresa",false,3,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());
// write your code here
}
public static class Human {
String name;
boolean sex;
int age;
static Human father;
static 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;
Human.father = father;
Human.mother = mother;}
// write your code here
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;
}
}
}