Чем мой вывод отличается от требуемого?
package com.javarush.task.task06.task0621;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Родственные связи кошек
*/
public class Solution {
public static class Cat
{
String name;
Cat catMother;
Cat catFather;
public Cat(String name,Cat catMother, Cat catFather)
{
this.name=name;
this.catMother=catMother;
this.catFather=catFather;
}
public String toString()
{
if (this.catMother==null && this.catFather==null)
return "The cat's name is "+this.name+", no mother, no father";
else if (this.catMother==null)
return "The cat's name is "+this.name+", no mother, father is "+this.catFather.name;
else if (this.catFather==null)
return "The cat's name is "+this.name+", mother is "+this.catMother.name+", no father";
else
return "The cat's name is "+this.name+", mother is "+this.catMother.name+", father is "+this.catFather.name;
}
}
public static void main(String[] args)
{
Scanner scanner=new Scanner(System.in);
Cat catGrandfather=new Cat(scanner.next()+" "+scanner.next(),null, null);
Cat catGrandmother=new Cat(scanner.next()+" "+scanner.next(),null, null);
Cat catFather=new Cat(scanner.next()+" "+scanner.next(), null, catGrandfather);
Cat catMother=new Cat(scanner.next()+" "+scanner.next(), catGrandmother, null);
Cat catSon=new Cat(scanner.next()+" "+scanner.next(), catMother, catFather);
Cat catDaughter=new Cat(scanner.next()+" "+scanner.next(), catMother, catFather);
scanner.close();
System.out.println(catGrandfather+"\n"+catGrandmother+"\n"+catFather+"\n"+catMother+"\n"+catSon+"\n"+catDaughter);
}
}