Пишет не прошла задача тест, а выводит результат правильно
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();
String grandmotherName = reader.readLine();
String fatherName = reader.readLine();
String motherName = reader.readLine();
String daughterName = reader.readLine();
String sonName = reader.readLine();
Cat catGrandfather = new Cat(grandfatherName);
Cat catGrandmother =new Cat(grandmotherName);
Cat catFather = new Cat (catGrandfather,fatherName);
Cat catMother = new Cat(motherName, catGrandmother);
Cat catDaughter = new Cat(daughterName, catMother,catFather);
Cat catSon = new Cat(sonName, catMother, catFather);
System.out.println(catGrandfather);
System.out.println(catGrandmother);
System.out.println(catFather);
System.out.println(catMother);
System.out.println(catDaughter);
System.out.println(catSon);
}
public static class Cat {
private String name;
private Cat mother;
private Cat father;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat mother) {
this.name = name;
this.mother =mother;
}
Cat(String name, Cat mother, Cat father) {
this.name = name;
this.mother = mother;
this.father=father;
}
Cat(Cat father, String name) {
this.name = name;
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)
return "The cat's name is " + name + ", no mother, is father " + father.name;
else if (father == null)
return "The cat's name is " + name + ", is mother"+ mother.name + " , no father ";
else
return "The cat's name is " + name + ", mother is " + mother.name + " father is" + father.name;
}
}
}