6 раз выводит
"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));
Cat dedushka = new Cat(reader.readLine(), null, null, null, null);
Cat babushka = new Cat(reader.readLine(), null, null, null, null);
Cat papa = new Cat(reader.readLine(), dedushka, null, null, null);
dedushka.sonSet(papa);
Cat mama = new Cat(reader.readLine(), null, babushka, null, null);
babushka.daughterSet(mama);
Cat sin = new Cat(reader.readLine(), papa, null, null, null);
papa.sonSet(sin);
mama.sonSet(sin);
Cat doch = new Cat(reader.readLine(), null, mama, null, null);
mama.daughterSet(doch);
papa.daughterSet(doch);
System.out.println(dedushka.toString());
System.out.println(babushka.toString());
System.out.println(papa.toString());
System.out.println(mama.toString());
System.out.println(sin.toString());
System.out.println(doch.toString());
}
public static class Cat {
private static String name;
private static Cat catFather;
private static Cat catMother;
private static Cat catSon;
private static Cat catDaughter;
Cat(String name, Cat catFather, Cat catMother, Cat catSon, Cat catDaughter){
this.name = name;
this.catFather = catFather;
}
public void sonSet(Cat cat){
this.catSon = cat;
}
public void daughterSet(Cat cat){
this.catDaughter = cat;
}
@Override
public String toString() {
if(Cat.catFather == null && Cat.catMother == null){
return "The cat's name is " + Cat.name + ", no mather" + ", no father";
}
else if(Cat.catFather != null && Cat.catSon != null){
return "The cat's name is " + Cat.name + ", no mather" + ", father is " + Cat.catFather;
}
else if(Cat.catMother != null && Cat.catDaughter != null){
return "The cat's name is " + Cat.name + ", mother is " + Cat.catMother + ", no father";
}
else if(Cat.catFather != null && Cat.catSon == null){
return "The cat's name is " + Cat.name + ", no mather" + ", father is " + Cat.catFather;
}
else if(Cat.catMother != null && Cat.catDaughter == null){
return "The cat's name is " + Cat.name + ", mother is " + Cat.catMother + ", no father";
}
else{return "lox";}
}
}
}