public class Solution {
public static void main(String[] args) {
List<Human> humanObj = new ArrayList<Human>();
humanObj.add(new Human("Vamsi",true,22));
humanObj.add(new Human("Vamsi1",true,22));
humanObj.add(new Human("Vamsi2",true,22));
humanObj.add(new Human("Vamsi3",true,22));
humanObj.add(new Human("Vamsi24",true,22,new Human("V",true,44),new Human("M",true,20)));
humanObj.add(new Human("Vamsi25",false,22,new Human("V",true,44),new Human("M",true,20)));
humanObj.add(new Human("Vamsi26",false,22,new Human("V",true,44),new Human("M",true,20)));
humanObj.add(new Human("Vamsi27",false,22,new Human("V",true,44),new Human("M",true,20)));
humanObj.add(new Human("Vamsi28",false,22,new Human("V",true,44),new Human("M",true,20)));
for(Human a : humanObj){
System.out.println(a);
}
// write your code here
}
package com.codegym.task.task07.task0724;
import java.util.*;
/*
Family census
*/
public class Solution {
public static void main(String[] args) {
List<Human> humanObj = new ArrayList<Human>();
humanObj.add(new Human("Vamsi",true,22));
humanObj.add(new Human("Vamsi1",true,22));
humanObj.add(new Human("Vamsi2",true,22));
humanObj.add(new Human("Vamsi3",true,22));
humanObj.add(new Human("Vamsi24",true,22,new Human("V",true,44),new Human("M",true,20)));
humanObj.add(new Human("Vamsi25",false,22,new Human("V",true,44),new Human("M",true,20)));
humanObj.add(new Human("Vamsi26",false,22,new Human("V",true,44),new Human("M",true,20)));
humanObj.add(new Human("Vamsi27",false,22,new Human("V",true,44),new Human("M",true,20)));
humanObj.add(new Human("Vamsi28",false,22,new Human("V",true,44),new Human("M",true,20)));
for(Human a : humanObj){
System.out.println(a);
}
// write your code here
}
public static class Human {
String name;
boolean sex;
int age;
Human father, 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;
}
// 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;
}
}
}