WHAT IS WRONG??
package com.codegym.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
/*
Cat relations
*/
public class Solution {
public static void main(String[] args) throws IOException {
Cat Grandfather = new Cat("Grandfather Tiger",null,null);
System.out.println(Grandfather);
Cat Grandmother = new Cat("Grandmother Puss", null, null);
System.out.println(Grandmother);
Cat Father = new Cat("Father Oscar",Grandfather,null);
System.out.println(Father);
Cat Mother = new Cat("Mother Missy",null,Grandmother);
System.out.println(Mother);
Cat Son = new Cat("Son Simba",Father,Mother);
System.out.println(Son);
Cat Daughter = new Cat("Daughter Coco",Father,Mother);
System.out.println(Daughter);
}
public static class Cat {
private String name;
private Cat father;
private Cat mother;
Cat(String name, Cat father, Cat mother) {
this.name = name;
this.father = father;
this.mother = mother;
}
@Override
public String toString() {
if (name != null && (mother == null) && (father == null)) {
return "The cat's name is " +name + ", no mother, no father";
} else if ((name != null) && (mother == null) && (father != null)) {
return "The cat's name is " + name + ", no mother, " + father.name + " is the father";
} else if ((name != null) && (mother != null) && (father == null)){
return "The cat's name is " + name + ", " + mother.name + " is the mother, no father";
} else if ((name != null) && (mother != null) && (father != null)){
return "The cat's name is " + name + ", " + mother.name + " is the mother, " + father.name + " is the father";
}
return null;
}
}
}