Подскажите, где может быть ошибка:и не пойму, почему при выводе на экран ругается на обращение к методу объекта toString, например System.out.println(grandfather.toString).
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,grandfatherName);
String motherName = reader.readLine();
Cat mother = new Cat(motherName,grandmotherName);
String sonName = reader.readLine();
Cat son = new Cat(sonName,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(son);
System.out.println(daughter);
}
public static class Cat {
private String name;
private String parent;
private String parent1;
public Cat(String name) {
this.name = name;
}
public Cat(String name, String parent) {
this.name = name;
this.parent = parent;
}
public Cat(String name, String parent, String parent1) {
this.name = name;
this.parent = parent;
this.parent1=parent1;
}
@Override
public String toString() {
if ((parent == null)&&(parent1 == null))
return ("The cat's name is " + name + ", no mother "+ ", no father ");
if ((parent.length()>0)&&(parent1 == null))
return ("The cat's name is " + name + ", mother is " + parent+ ", no father ");
if ((parent1.length()>0)&&(parent == null))
return "The cat's name is " + name + ",no mother " + ", father is "+parent1;
if ((parent1.length()>0)&&(parent.length()>0))
return "The cat's name is " + name + ", mother is " + parent+ ", father is "+parent1;
}
}
}