Выводит в ответе:
The cat's name is папа Котофей, no mother, no father
The cat's name is мама Василиса, mother is бабушка Мурка, no father
The cat's name is сын Мурчик, mother is мама Василиса, no father
The cat's name is дочь Пушинка, mother is мама Василиса, 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 grandfName= reader.readLine();
Cat catGrandf = new Cat(grandfName, null, null);
String grandmName = reader.readLine();
Cat catGrandm =new Cat(grandmName, null, null);
String fatherName = reader.readLine();
Cat catFather = new Cat(fatherName, null, catGrandf);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName,catGrandm,null);
String sonName = reader.readLine();
Cat catSon = new Cat(sonName, catMother,catFather);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName,catMother,catFather );
System.out.println(catGrandf);
System.out.println(catGrandm);
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 parent2;
Cat(String name, Cat parent2, Cat parent) {
this.name = name;
this.parent = parent;
this.parent = parent2;
}
@Override
public String toString() {
if (parent == null&& parent2==null)
return "The cat's name is " + name + ", no mother, no father ";
else if (parent == null&& parent2!=null)
return "The cat's name is " + name + ", no mother, father is "+ parent2.name;
else if (parent != null&& parent2==null)
return "The cat's name is " + name + ", mother is "+ parent.name+", no father";
else
return "The cat's name is " + name + ", mother is " + parent.name+" father is "+parent2.name;
}
}
}