Вроде всё норм. При вводе данных из примера получаю вывод как из примера.
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 grenydadName = reader.readLine();
Cat catGrenydad = new Cat(grenydadName);
String grenymomName = reader.readLine();
Cat catGrenymom = new Cat(grenymomName);
String fatherName = reader.readLine();
Cat catFather = new Cat(fatherName, catGrenydad);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName, catGrenymom);
String SunName = reader.readLine();
Cat catSun = new Cat(SunName, catMother, catFather);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName, catMother, catFather);
System.out.println(catGrenydad);
System.out.println(catGrenymom);
System.out.println(catFather);
System.out.println(catMother);
System.out.println(catSun);
System.out.println(catDaughter);
}
public static class Cat {
private String name;
private Cat Mother;
private Cat Father;
public static int count=0;
Cat(String name) {
this.name = name;
count++;
}
Cat(String name, Cat parents) {
this.name = name;
count++;
if(count==3)
this.Father = parents;
else
this.Mother = parents;
}
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((Mother == null)&&(Father != null))
// "The cat's name is папа Котофей, no mother, father is дедушка Вася"
return "The cat's name is " + name + ", no mother, father is "+Father.name;
else if((Mother != null)&&(Father != null))
return "The cat's name is " + name + ", mother is "+Mother.name+", father is "+Father.name;
else return null;
}
}
}