In intelij Idea everythinkg works...but here It cannot compile it. Why?
com/codegym/task/task08/task0824/Solution.java:20: error: <identifier> expected
olderChilds1.add(father);
package com.codegym.task.task08.task0824;
/*
Make a family
*/
import java.util.*;
public class Solution {
ArrayList<Human> childs = new ArrayList<>();
ArrayList<Human> olderChilds1 = new ArrayList<>();
ArrayList<Human> olderChilds2 = new ArrayList<>();
ArrayList<Human> nochilds = new ArrayList<>();
Human grandfather1 = new Human("Aleksandr", true, 57, olderChilds1);
Human grandfather2 = new Human("Maxim", true, 54, olderChilds2);
Human grandmother1 = new Human("Marina", false, 58, olderChilds1);
Human grandmother2 = new Human("Kasandra", false, 54, olderChilds2);
Human father = new Human("Morin", true, 30, childs);
olderChilds1.add(father);
Human mother = new Human("Drixy", false, 28, childs);
olderChilds2.add(mother);
Human child1 = new Human("Edward", true, 6, nochilds);
childs.add(child1);
Human child2 = new Human("Nancy", false, 4, nochilds);
childs.add(child2);
Human child3 = new Human("Max", true, 2, nochilds);
childs.add(child3);
System.out.println(grandfather1);
System.out.println(grandfather2);
System.out.println(grandmother1);
System.out.println(grandmother2);
System.out.println(father);
System.out.println(mother);
System.out.println(child1);
System.out.println(child2);
System.out.println(child3);
}
// two grandfathers, two grandmothers, one father, one mother, and three children.
public static class Human {
String name;
boolean sex;
int age;
ArrayList<Human> children;
public Human(String name, boolean sex, int age, ArrayList<Human> children){
this.name = name;
this.sex = sex;
this.age = age;
this.children = children;
}
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;
}
}
}