Вывод
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 папа Котофей
вроде все верно, помогите найти ошибку, никак не пойму что не так.
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 grandfatherName = reader.readLine();
Cat grandFather = new Cat(grandfatherName);
String grandmotherName = reader.readLine();
Cat grandMother = new Cat(grandmotherName);
String fatherName = reader.readLine();
Cat catFather = new Cat(fatherName, grandFather, null);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName, null, grandMother);
String sonName = reader.readLine();
Cat son = new Cat(sonName, catFather, catMother);
String doughterName = reader.readLine();
Cat doughter = new Cat(doughterName, catFather, catMother);
System.out.println(grandFather);
System.out.println(grandMother);
System.out.println(catFather);
System.out.println(catMother);
System.out.println(son);
System.out.println(doughter);
}
public static class Cat {
private String name;
private Cat father;
private Cat mother;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat father, Cat mother) {
this.name = name;
this.father = father;
this.mother = mother;
}
@Override
public String toString() {
if (father == null && mother == null) {
return "The cat`s name is " + name + ", no mother, no father";
} else if (father != null && mother == null) {
return "The cat`s name is " + name + ", no mother, " + "father is " + father.name;
} else if (father == null && mother != null) {
return "The cat`s name is " + name + ", mother is " + mother.name + ", no father";
} else return "The cat`s name is " + name + ", mother is " + mother.name + ", father is " + father.name;
}
}
}