Не проходит валидацию по следующим условиям:
Строка про папу (третья) должна соответствовать условию.
Строка про маму (четвертая) должна соответствовать условию.
Please help...
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 Father = new Cat(FatherName, grandFather, null);
String MotherName = reader.readLine();
Cat Mother = new Cat(MotherName, null, grandMother);
String SonName = reader.readLine();
Cat Son = new Cat(SonName, grandFather, grandFather, Father, Mother);
String DaughterName = reader.readLine();
Cat Daughter = new Cat(DaughterName, grandFather, grandMother, Father, Mother);
System.out.println(grandFather);
System.out.println(grandMother);
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 grandPa;
private Cat grandMa;
private Cat Pa;
private Cat Ma;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat grandPa, Cat grandMa) {
this.name = name;
this.grandPa = grandPa;
this.grandMa = grandMa;
}
Cat(String name, Cat grandPa, Cat grandMa, Cat Pa, Cat Ma) {
this.name = name;
this.grandPa = grandPa;
this.grandMa = grandMa;
this.Pa = Pa;
this.Ma = Ma;
}
@Override
public String toString() {
if (Pa == null && Ma == null)
return "The cat's name is " + name + ", no mother, no father";
else if (grandMa == null)
return "The cat's name is " + name + ", no mother, father is" + " " + grandPa.name;
else if (grandPa == null)
return "The cat's name is " + name + ", mother is" + " " + grandMa.name + " " + "no father";
else
return "The cat's name is " + name + ", mother is" + " " + Ma.name + " " + ", father is" + " " + Pa.name;
}
}
}