package com.codegym.task.task07.task0724;
/*
Family census
*/
public class Solution {
public static void main(String[] args) {
Human gF1 = new Human("Dodoo", true, 78);
Human gM1 = new Human("Ayele", false, 75);
Human gF2 = new Human("Sowa Tetteh", true, 75);
Human gM2 = new Human("Anye", false, 70);
Human Father = new Human("Lan Tei", true, 52, gF2, gM2);
Human Mother = new Human("Koshie", false, 50, gF1, gM1);
Human child1 = new Human("Leroy", true, 40, Father,Mother);
Human child2 = new Human("Ayishetu", false, 30, Father, Mother);
Human child3 = new Human("Ramatu", false, 27, Father, Mother);
System.out.println(child1+""+
child2+""+
child3
);
// write your code here
}
public static class Human {
// write your code here
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 += "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 gF1 = new Human("Dodoo", true, 78);
Human gM1 = new Human("Ayele", false, 75);
Human gF2 = new Human("Sowa Tetteh", true, 75);
Human gM2 = new Human("Anye", false, 70);
Human Father = new Human("Lan Tei", true, 52, gF2, gM2);
Human Mother = new Human("Koshie", false, 50, gF1, gM1);
Human child1 = new Human("Leroy", true, 40, Father,Mother);
Human child2 = new Human("Ayishetu", false, 30, Father, Mother);
Human child3 = new Human("Ramatu", false, 27, Father, Mother);
System.out.println(child1+""+
child2+""+
child3
);
// write your code here
}
public static class Human {
// write your code here
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 += "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;
}
}
}