Не могу понять в чем проблема, вывод корректный. Помогите, пожалуйста.
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, grandfatherName);
String grandmotherName = reader.readLine();
Cat grandmother = new Cat( grandmotherName, grandmotherName);
String fatherName = reader.readLine();
Cat father = new Cat( fatherName,grandfather, fatherName);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName,grandmother, motherName);
String sonName = reader.readLine();
Cat son = new Cat(sonName, catMother ,father, sonName);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName, catMother ,father, daughterName);
System.out.println(grandfather);
System.out.println(grandmother);
System.out.println(father);
System.out.println(catMother);
System.out.println(son);
System.out.println(catDaughter);
}
public static class Cat {
private String name;
private Cat mother;
private Cat father;
private String gender;
Cat(String name) {
this.name = name;
}
Cat(String name, String gender) {
this.name = name;
this.gender = defineGender(gender);
}
Cat(String name, Cat mother, Cat father, String gender) {
this.name = name;
this.mother = mother;
this.father = father;
this.gender = defineGender(gender);
}
Cat(String name, Cat parent, String gender) {
this.name = name;
if(parent.gender =="F") this.mother = parent;
if(parent.gender =="M") this.father = parent;
this.gender = gender;
}
@Override
public String toString() {
if (father == null && mother == null) {
return "The cat's name is " + name + ", no mother, no father";
} else {
if (father == null && mother != 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 + ", no mother, father is " + father.name;
} else {
return "The cat's name is "+ name+", mother is " + mother.name + ", father is " + father.name;
}
}
}
}
public String defineGender (String cat){
if( cat.contains("бабушка") || cat.contains("мама")||cat.contains("дочь")){
return "F";
} else return "M";
}
}
}