Кидает NullPointException на 69 строке, подскажите где мой фэйл
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));
String grandFatherName = reader.readLine();
Cat grandFather = new Cat(grandFatherName);
String grandMotherName = reader.readLine();
Cat grandMother = new Cat(grandMotherName);
String fatherName = reader.readLine();
Cat father = new Cat(fatherName, null, grandFatherName);
String motherName = reader.readLine();
Cat mother = new Cat(motherName, grandMotherName);
String sunName = reader.readLine();
Cat sun = new Cat(sunName, motherName, fatherName);
String daughterName = reader.readLine();
Cat daughter = new Cat(daughterName, motherName, fatherName);
System.out.println(grandFather);
System.out.println(grandMother);
System.out.println(father);
System.out.println(mother);
System.out.println(sun);
System.out.println(daughter);
}
public static class Cat {
private String name;
private Cat mother;
private Cat father;
Cat(String name) {
this.name = name;
}
Cat(String name, String motherName) {
this.name = name;
this.mother = new Cat(motherName);
}
Cat(String name, String motherName, String fatherName){
if(motherName == null){
this.name = name;
this.father = new Cat(fatherName);
} else {
this.name = name;
this.mother = new Cat(motherName);
this.father = new Cat(fatherName);
}
}
@Override
public String toString() {
if (mother.name == null && father.name == null)
return "The cat's name is " + name + ", no mother, no father";
else if(mother.name == null)
return "The cat's name is " + name + ", no mother, father is " + father.name;
else if(father.name == null)
return "The cat's name is " + name + ", mother is " + mother.name + ", no father";
else
return "The cat's name is " + name + ", mother is " + mother.name + ", father is " + father.name;
}
}
}