Валидатор ругается на "Строка про папу (третья) должна соответствовать условию". Вопрос: что я пропустил?
Собственно вывод программы:
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));
Cat grandpa = new Cat(reader.readLine());
Cat grandma = new Cat(reader.readLine());
Cat father = new Cat(reader.readLine(), grandpa);
Cat mother = new Cat(reader.readLine(), grandma);
Cat son = new Cat(reader.readLine(), mother, father);
Cat daughter = new Cat(reader.readLine(), mother, father);
System.out.println(grandpa);
System.out.println(grandma);
System.out.println(father);
System.out.println(mother);
System.out.println(son);
System.out.println(daughter);
}
public static class Cat {
private String name;
private Cat mother;
private Cat father;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat parent) {
this.name = name;
String[] a = {"дедушка", "папа", "сын"};
String[] b = parent.name.split(" ");
if(b[0].equals(a[0]) || b[0].equals(a[1]) || b[0].equals(a[2])) {
this.father = parent;
}
else {
this.mother = parent;
}
}
Cat(String name, Cat mother, Cat father) {
this.name = name;
this.mother = mother;
this.father = father;
}
@Override
public String toString() {
if (mother == null & father == null){
return "The cat's name is " + name + ", no mother, no father ";
}
else if (mother == null & father != null){
return "The cat's name is " + name + ", no mother, father is " + father.name;
}
else if (mother != null & father == 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;
}
}
}
}