THIS IS THE ERROR I am getting..
method addAll in class java.util.Collections cannot be applied to given types; required: java.util.Collection<? super
Line 27 is the error message..
package com.codegym.task.task08.task0824;
/*
Make a family
*/
import java.util.*;
public class Solution {
public static void main(String[] args) {
//write your code here
ArrayList<Human> childrenYounger = new ArrayList<>();
ArrayList<Human> childrenMother = new ArrayList<>();
ArrayList<Human> childrenFather = new ArrayList<>();
Human grandfather1 = new Human("Bob", true, 67, childrenFather);
Human grandfather2 = new Human("Tom", true,77, childrenMother );
Human grandmother1 = new Human("Susan", false,66, childrenFather);
Human grandmother2 = new Human("Mary", false, 56, childrenMother);
Human father = new Human("Bill", true, 40, childrenYounger);
Human mother = new Human("Balbina", false,38, childrenYounger);
Human child1 = new Human("Cathlyn", false, 12, new ArrayList<>());
Human child2 = new Human("Ben", true,13, new ArrayList<>());
Human child3 = new Human("Maja", false, 14, new ArrayList<>());
Collections.addAll(childrenYounger,child1,child2,child3);
Collections.addAll(childrenFather,childrenMother,father,mother);
System.out.println(grandfather1.toString());
System.out.println(grandfather2.toString());
System.out.println(grandmother1.toString());
System.out.println(grandmother2.toString());
System.out.println(father.toString());
System.out.println(mother.toString());
System.out.println(child1.toString());
System.out.println(child2.toString());
System.out.println(child3.toString());
}
public static class Human {
//write your code here
String name;
boolean sex;
int age;
ArrayList <Human> children = new ArrayList<>();
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;
}//end of for loop
}//end of if
return text;
}//end of toString
}// end of Human
}//end of main