Identifier expected error when i try to print the objects, anybody know what is wrong?
package com.codegym.task.task08.task0824;
/*
Make a family
*/
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
//write your code here
Human c1 = new Human("jenny", 12, false, new ArrayList<Human>());
Human c2 = new Human("john", 6, true, new ArrayList<Human>());
Human c3 = new Human("jake", 5, true, new ArrayList<Human>());
ArrayList<Human> children = new ArrayList<>(), father = new ArrayList<>(), mother = new ArrayList<>();
children.add(c1);
children.add(c2);
children.add(c3);
Human f = new Human("Jerry", 50, true, children);
Human m = new Human("Bellie", 42, false, children);
father.add(f);
mother.add(c);
Human gf1 = new Human("Jose", 90, true, father);
Human gf2 = new Human("June", 80, true, mother);
Human gm1 = new Human("Nely", 85, false, father);
Human gm2 = new Human("Mellisa", 79, false, mother);
}
System.out.println(c1.toString());
System.out.println(c2.toString());
System.out.println(c3.toString());
System.out.println(m.toString());
System.out.println(f.toString());
System.out.println(gf1.toString());
System.out.println(gf2.toString());
System.out.println(gm1.toString());
System.out.println(gm2.toString());
public static class Human {
//write your code here
public String name;
public int age;
public boolean sex;
public ArrayList<Human> children;
public Human(String name, int age, boolean sex, ArrayList<Human> children){
this.name = name;
this.age = age;
this.sex = sex;
this.children = children;
}
public Human(String name, int age, boolean sex){
this.name = name;
this.age = age;
this.sex = sex;
}
public String toString() {
String text = "";
text += "Name: " + this.name;
text += ", sex: " + (this.sex ? "male" : "female");
text += ", age: " + this.age;
int childCount = this.children.size();
if (childCount > 0) {
text += ", children: " + this.children.get(0).name;
for (int i = 1; i < childCount; i++) {
Human child = this.children.get(i);
text += ", " + child.name;
}
}
return text;
}
}
}