НУЖНА ПОМОЩЬ ОБЬЯСНИТЕ ,ЧТО В ПОСЛЕДНИХ 2 УСЛОВИЯХ НЕ ПРАВИЛЬНО
package com.javarush.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Родственные связи кошек
The cat's name is дедушка Вася, no mother, no father
The cat's name is бабушка Мурка, no mother, no father
The cat's name is папа Котофей, no mother, father is дедушка Вася
The cat's name is мама Василиса, mother is бабушка Мурка, no father
The cat's name is сын Мурчик, mother is мама Василиса, father is папа Котофей
The cat's name is дочь Пушинка, mother is мама Василиса, father is папа Котофей
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String oldCatFather = reader.readLine();
Cat catOldFather = new Cat(oldCatFather);
String oldCatMather = reader.readLine();
Cat catOldMather = new Cat(oldCatMather);
String father = reader.readLine();
Cat catFather = new Cat(father,catOldFather,null);
String mather = reader.readLine();
Cat catMather = new Cat(mather,null,catOldMather);
String son = reader.readLine();
Cat catSon = new Cat(son,catMather,catFather);
String daughter = reader.readLine();
Cat catDaughter = new Cat(daughter,catMather,catFather);
System.out.println(catOldFather);
System.out.println(catOldMather);
System.out.println(catFather);
System.out.println(catMather);
System.out.println(catSon);
System.out.println(catDaughter);
}
public static class Cat {
private String name;
private Cat father;
private Cat mather;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat father ,Cat mather) {
this.name = name;
this.father = father;
this.mather = mather;
}
@Override
public String toString() {
if (mather == null && father == null){
return "The cat's name is " + name + ", no mother, no father";
}
if (mather == null){
return "The cat's name is " + name + ", no mother, father is " + father.name + "";
}
if (father == null){
return "The cat's name is " + name + ", mother is " + mather.name + ", no father";
}
if (mather != null && father != null){
return "The cat's name is " + name + ", mother is " + mather.name + ", father is " + father.name + "";
}
if (father != null && mather != null){
return "The cat's name is " + name + ", mother is " + mather.name + ", father is " + father.name + "";
}
return null;
}
}
}