Вроде ж всё правильно, но текст не такой как у них((((((((((((((
У меня на выводе:
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 дедушка Вася, no mother, no father
The cat's name is мама Василиса, mother is The cat's name is бабушка Мурка, no mother, no father, no father
The cat's name is сын Мурчик, mother is The cat's name is мама Василиса, mother is The cat's name is бабушка Мурка, no mother, no father, no father, father is The cat's name is папа Котофей, no mother, father is The cat's name is дедушка Вася, no mother, no father
The cat's name is дочь Пушинка, mother is The cat's name is мама Василиса, mother is The cat's name is бабушка Мурка, no mother, no father, no father, father is The cat's name is папа Котофей, no mother, father is The cat's name is дедушка Вася, no mother, no father
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 dedName = reader.readLine();
Cat catDed = new Cat(dedName, null, null);
String BabkaName = reader.readLine();
Cat catBabka = new Cat(BabkaName, null, null);
String papaName = reader.readLine();
Cat catPapa = new Cat(papaName, null, catDed);
String mamaName = reader.readLine();
Cat catMama = new Cat(mamaName, catBabka, null);
String sinName = reader.readLine();
Cat catSin = new Cat(sinName, catMama, catPapa);
String dochkaName = reader.readLine();
Cat catDochka = new Cat(dochkaName, catMama, catPapa);
System.out.println(catDed);
System.out.println(catBabka);
System.out.println(catPapa);
System.out.println(catMama);
System.out.println(catSin);
System.out.println(catDochka);
}
public static class Cat {
private String name;
private Cat mama;
private Cat papa;
/*Cat(String name) {
this.name = name;
}
Cat(String name, Cat parent) {
this.name = name;
this.mama = mama;
}*/
//???????????????????
Cat(String name, Cat mama, Cat papa) {
this.name = name;
this.mama = mama;
this.papa = papa;
}
//???????????????????
@Override
public String toString() {
if ((papa == null) && (mama == null))
return "The cat's name is " + name + ", no mother, no father";
else
if (papa == null)
return "The cat's name is " + name + ", mother is " + mama + ", no father";
else
if (mama == null)
return "The cat's name is " + name + ", no mother, father is " + papa;
else return "The cat's name is " + name + ", mother is " + mama + ", father is " + papa;
}
}
}