I tried since a little while to get this task solved but itt didn't pass fhe verification and I don't know what's wrong?
May I have some help?
Thanks.
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 catGrandFatherName = new Cat(grandfatherName, null, null);
String grandmotherName = reader.readLine();
Cat catGrandMotherName = new Cat(grandmotherName, null, null);
String fatherName = reader.readLine();
Cat catFatherName = new Cat(fatherName, null, catGrandFatherName);
String motherName = reader.readLine();
Cat catMotherName = new Cat(motherName, catGrandMotherName, null);
String sonName = reader.readLine();
Cat catSonName = new Cat(sonName, catMotherName, catFatherName);
String daugtherName = reader.readLine();
Cat catDaughterName = new Cat(daugtherName, catMotherName, catFatherName);
System.out.println(catGrandFatherName);
System.out.println(catGrandMotherName);
System.out.println(catFatherName);
System.out.println(catMotherName);
System.out.println(catSonName);
System.out.println(catDaughterName);
}
public static class Cat {
private String name;
private Cat mother, father;
Cat(String name, Cat mother, Cat father) {
this.name = name;
this.mother = mother;
this.father = father;
}
@Override
public String toString() {
String res = null;
if (mother == null && father == null) {
res = "The cat´s name is " + name + ", no mother, no father";
} else if (mother != null && father == null) {
res = "The cat´s name is " + name + ", " + mother.name + " is the mother, no father";
} else if (mother == null && father != null) {
res = "The cat´s name is " + name + ", no mother, " + father.name + " is the father";
} else if (mother != null && father != null) {
res = "The cat's name is " + name + ", " + mother.name + " is the mother, " + father.name + " is the father";
}
return res;
}
}
}