Что не так? Выводит все верно!!! Я проверил все запятые и знаки препинания, но...
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 catGrandFather = new Cat("дедушка " + grandFatherName);
String grandMotherName = reader.readLine();
Cat catGrandMother = new Cat("бабушка " + grandMotherName);
String FatherName = reader.readLine();
Cat catFather = new Cat("папа " + FatherName, "дедушка " + grandFatherName);
String motherName = reader.readLine();
Cat catMother = new Cat("мама " + motherName, "бабушка " + grandMotherName , null);
String sunName = reader.readLine();
Cat catSun = new Cat("сын " + sunName, "мама " + motherName, "папа " + FatherName);
String daughterName = reader.readLine();
Cat catDaughter = new Cat("дочь " + daughterName, "мама " + motherName, "папа " + FatherName);
System.out.println(catGrandFather);
System.out.println(catGrandMother);
System.out.println(catFather);
System.out.println(catMother);
System.out.println(catSun);
System.out.println(catDaughter);
}
public static class Cat {
private String name;
private String parentFather;
private String parentMother;
Cat(String name) {
this.name = name;
}
Cat(String name, String parentFather) {
this.name = name;
this.parentFather = parentFather;
}
Cat(String name, String parentMother, String parentFather) {
this.name = name;
this.parentFather = parentFather;
this.parentMother = parentMother;
}
@Override
public String toString() {
if (parentFather == null && parentMother == null){
return "Cat name is " + name + ", no mother" + ", no father";
}
else if (parentFather == null){
return "Cat name is " + name + ", mother is " + parentMother + ", no father";
}
else if (parentMother == null){
return "Cat name is " + name + ", no mother" + ", father is " + parentFather;
}
else {
return "Cat name is " + name + ", mother is " + parentMother + ", father is " + parentFather;
}
}
}
}