Непонимаю в чем ошибка. Подскажите пожалуйста. Глаза уже красные, перешивал уже несколько раз. О каких условиях вообще идет речь???
Вывод в Idea:
Cat name is дедушка Вася, no mother, no father
Cat name is бабушка Мурка, no mother, no father
Cat name is папа Котофей, no mother, father is дедушка Вася
Cat name is мама Василиса, mother is бабушка Мурка, no father
Cat name is сын Мурчик, mother is мама Василиса, father is папа Котофей
Cat name is дочь Пушинка, mother is мама Василиса, father is папа Котофей
Условия:
Cat name is дедушка Вася, no mother, no father
Cat name is бабушка Мурка, no mother, no father
Cat name is папа Котофей, no mother, father is дедушка Вася
Cat name is мама Василиса, mother is бабушка Мурка, no father
Cat name is сын Мурчик, mother is мама Василиса, father is папа Котофей
Cat name is дочь Пушинка, mother is мама Василиса, father is папа Котофей
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 r = new BufferedReader(new InputStreamReader(System.in));
Cat catGrandFather = new Cat(r.readLine());
Cat catGrandMother = new Cat(r.readLine());
Cat catFather = new Cat(r.readLine(),catGrandFather, null);
Cat catMother = new Cat(r.readLine(),null, catGrandMother);
Cat catSon = new Cat(r.readLine(), catFather, catMother);
Cat catDaughter = new Cat(r.readLine(), catFather, catMother);
System.out.println(catGrandFather);
System.out.println(catGrandMother);
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 father; private Cat mother;
Cat(String name) {this.name = name;}
Cat(String name, Cat f_var, Cat m_var) {this.name = name; this.father = f_var; this.mother = m_var;}
@Override
public String toString()
{if ((mother == null) && (father == null)) return "Cat name is " + name + ", no mother, no father";
else if (mother == null) return "Cat name is " + name + ", no mother, father is " + father.name;
else if (father == null) return "Cat name is " + name + ", mother is " + mother.name + ", no father";
else return "Cat name is " + name + ", mother is " + mother.name + ", father is " + father.name;}}}