Что не так сделал?
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 gfatherName = reader.readLine();
Cat catgfather = new Cat(gfatherName);
String gmotherName = reader.readLine();
Cat catgmother = new Cat(gmotherName);
String fatherName = reader.readLine();
Cat catfather = new Cat (catgfather, fatherName);
String motherName = reader.readLine();
Cat catmother = new Cat(motherName, catgmother);
String sonName = reader.readLine();
Cat catson = new Cat(sonName, catmother, catgfather);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName, catmother, catgfather);
System.out.println(catgfather);
System.out.println(catgmother);
System.out.println(catfather);
System.out.println(catmother);
System.out.println(catson);
System.out.println(catDaughter);
}
public static class Cat {
private String name;
private Cat parent;
private Cat parentgf;
private Cat parentgm;
private Cat parent1;
Cat(String name) {
this.name = name;
}
Cat(Cat parentgf, String name) {
this.name = name;
this.parentgf = parentgf;
}
Cat(String name, Cat parentgm) {
this.name = name;
this.parentgm = parentgm;
}
Cat(String name, Cat parent, Cat parent1) {
this.name = name;
this.parent = parent;
this.parent1 = parent1;
}
@Override
public String toString() {
if (parent == null)
return "The cat's name is " + name + ", no mother, no father";
else if (parentgf != null)
return "The cat's name is " + name + ", no mother, father is " + parentgf;
else if (parentgm != null)
return "The cat's name is " + name + ", mother is " + parentgm + ", no father";
if (parent1 != null)
return "The cat's name is " + name + ", mother is " + parent + ", father is " + parent1;
else return null;
}
}
}