Друзья, почему кидает NullPointerException???
package com.javarush.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Родственные связи кошек
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Cat grandFather = new Cat(reader.readLine(), null, null);
Cat grandMother= new Cat(reader.readLine(), null, null);
Cat father = new Cat(reader.readLine(), null, grandFather);
Cat mother = new Cat(reader.readLine(), grandMother, null);
Cat son = new Cat(reader.readLine(), mother, father);
Cat daughter = new Cat(reader.readLine(), mother, father);
System.out.println(grandFather);
System.out.println(grandMother);
System.out.println(father);
System.out.println(mother);
System.out.println(son);
System.out.println(daughter);
}
public static class Cat {
private String name;
private Cat father;
private Cat mother;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat mother, Cat father) {
this.name = name;
this.mother = mother;
this.father = father;
}
@Override
public String toString() {
if (mother == null && father == null){
return "The cat's name is " + name + ", no mother" + ", no father";
}else if (mother == null && father != null){
return "The cat's name is " + name + ", mother is " + mother.name + ", no father";
}else if (father == null && mother != null){
return "The cat's name is " + name + ", mother is " + mother.name + ", father is " + father.name;
} else{
return "The cat's name is " + name + ", mother is " + mother.name + ", father is " + father.name;
}
}
}
}