Битый час ломаю голову ошибку найти не могу
package com.javarush.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Родственные связи кошек
*/
public class Solution {
//Программа должна считывать имена 6 котов в указанном порядке.
//• Метод main должен создавать 6 объектов типа Cat.
//• Программа должна выводить 6 строк с информацией о котах.
//• Строка про дедушку (первая) должна соответствовать условию.
//• Строка про бабушку (вторая) должна соответствовать условию.
//• Строка про папу (третья) должна соответствовать условию.
//• Строка про маму (четвертая) должна соответствовать условию.
//• Строка про сына (пятая) должна соответствовать условию.
//• Строка про дочь (шестая) должна соответствовать условию.
/*
Родственные связи кошек
*/
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String grandFather1 = reader.readLine();
Cat grandFather = new Cat(grandFather1);
String grandMother1 = reader.readLine();
Cat grandMother = new Cat(grandMother1);
String father1 = reader.readLine();
Cat father = new Cat(father1, grandFather);
String mother1 = reader.readLine();
Cat mother = new Cat(mother1, grandMother, null);
String son1 = reader.readLine();
Cat son = new Cat(son1, mother, father);
String daughther1 = reader.readLine();
Cat daughther = new Cat(daughther1, 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(daughther);
}
public static class Cat {
private String name;
private Cat father;
private Cat mother;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat father) {
this.name = name;
this.father = father;
}
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) {
return "The cat's name is " + name + ", mother is " + mother.name + ", no father";
} else if (father == null) {
return "The cat's name is " + name + ", no mother " + ", father is " + father.name;
} else {
return "The cat's name is " + name + ", mother is " + mother.name + ", father is " + father.name;
}
}
}
}