Помогите разобраться, пожалуйста
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 grandpaName = reader.readLine();
Cat catGrandpa = new Cat(grandpaName, null, null);
String grandmaName = reader.readLine();
Cat catGrandma = new Cat(grandmaName, null, null);
String dadName = reader.readLine();
Cat catDad = new Cat(dadName, null, catGrandpa);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName, catGrandma, null);
String sonName = reader.readLine();
Cat catSon = new Cat(sonName, catMother, catDad);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName, catMother, catDad);
System.out.println(catGrandpa);
System.out.println(catGrandma);
System.out.println(catDad);
System.out.println(catMother);
System.out.println(catSon);
System.out.println(catDaughter);
}
public static class Cat {
private String name;
private Cat parentmom;
private Cat parentdad;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat parentmom, Cat parentdad) {
this.name = name;
this.parentmom = parentmom;
this.parentdad = parentdad;
}
@Override
public String toString() {
if (parentmom == null && parentdad == null)
return "The cat's name is " + name + ", no mother, no father";
else if (parentmom != null && parentdad == null)
return "The cat's name is " + name + ", mother is " + parentmom.name + ", no father";
else if (parentmom == null && parentdad != null)
return "The cat's name is " + name + ", no mother, father is " + parentdad.name;
else if (parentmom != null && parentdad != null)
return "The cat's name is " + name + ", mother is " + parentmom.name + " father is " + parentdad.name;
}
}
}