Да что не так??
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));
Cat grandFather = new Cat(reader.readLine());
Cat grandMother = new Cat(reader.readLine());
Cat father = new Cat(reader.readLine(),grandFather);
Cat mather = new Cat(reader.readLine(),grandMother);
Cat child1 = new Cat(reader.readLine(),father,mather);
Cat child2 = new Cat(reader.readLine(),father,mather);
System.out.println(grandFather.toString());
System.out.println(grandMother.toString());
System.out.println(father.toString());
System.out.println(mather.toString());
System.out.println(child1.toString());
System.out.println(child2.toString());
}
public static class Cat {
private String name;
private Cat mather;
private Cat father;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat mather, Cat father) {
this.name = name;
this.mather = mather;
this.father = father;
}
Cat(String name, Cat parent) {
this.name = name;
this.mather = parent; }
@Override
public String toString() {
if (mather == null && father!=null){
return "The cat's name is " + name + ", no mother, father is " + father.name;
}
if (mather != null && father==null){
return "The cat's name is " + name + ", no father, mother is " + mather.name;
}
if (mather == null && father == null)
return "The cat's name is " + name + ", no mother, no father";
else
return "The cat's name is " + name + ", mother is " + mather.name + ", father is " + father.name;
}
}
}