Guys,
can you help me out?
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
Exception in thread "main" java.lang.NullPointerException
at Lvevel8FinalTasks.MakeAFamily.MakeAFamily.main(MakeAFamily.java:15)
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 child1 = new Human("child1", false, 20);
Human child2 = new Human("child2", true, 25);
Human child3 = new Human("child3", true, 28);
Human father = new Human("F1",true, 50);
father.children.add(child1);
father.children.add(child2);
father.children.add(child3);
Human mother = new Human("M1",false,40);
mother.children.add(child1);
mother.children.add(child2);
mother.children.add(child3);
Human grandF1 = new Human("Gf1", true,80);
grandF1.children.add(father);
Human grandF2 = new Human("Gf2", true, 70);
grandF2.children.add(mother);
Human grandM1 = new Human("GM1", false, 69);
grandM1.children.add(father);
Human grandM2 = new Human("GM2", false,80);
grandM2.children.add(mother);
System.out.println(grandF1);
System.out.println(grandF2);
System.out.println(grandM1);
System.out.println(grandM2);
System.out.println(father);
System.out.println(mother);
System.out.println(child1);
System.out.println(child3);
System.out.println(child3);
}
public static class Human {
//write your code here
String name;
boolean sex;
int age;
ArrayList<Human> children;
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, 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;
}
}
}