please check my code,what's wrong in my code ,last 2 conditions not satisfied
package com.codegym.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Cat relations
*/
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, null, Grandfather);
String motherName = reader.readLine();
Cat Mother = new Cat(motherName, Grandmother, null);
String sonname = reader.readLine();
Cat Son = new Cat(sonname, Mother, Father);
String daughtername = reader.readLine();
Cat Daughter = new Cat(daughtername, Mother, Father);
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 mother;
private Cat father;
Cat(String name) {
this.name = name;
}
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.name + ", is the father";
else if(father == null && mother != null)
return "The cat's name is " + name + " ," + mother.name + ", is the mother " + " , no father";
else
return"the cat's name is " + name + ", " + mother.name + " is the mother, " + father.name + " is the father";
}
}
}