Подскажите пожалуйста . Спасибо
package com.javarush.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Новая задача: У каждой кошки есть имя, кот-папа и кошка-мама.
Изменить класс Cat так, чтобы он мог описать данную ситуацию.
Создать 6 объектов: дедушку (папин папа), бабушку (мамина мама), папу, маму, сына, дочь.
Вывести их всех на экран в порядке: дедушка, бабушка, папа, мама, сын, дочь.
Пример ввода:
дедушка Вася
бабушка Мурка
папа Котофей
мама Василиса
сын Мурчик
дочь Пушинка
Пример вывода:
The cat's name is дедушка Вася, no mother, no father
The cat's name is бабушка Мурка, no mother, no father
The cat's name is папа Котофей, no mother, father is дедушка Вася
The cat's name is мама Василиса, mother is бабушка Мурка, no father
The cat's name is сын Мурчик, mother is мама Василиса, father is папа Котофей
The cat's name is дочь Пушинка, mother is мама Василиса, father is папа Котофей
Требования:
1. Программа должна считывать имена 6 котов в указанном порядке.
2. Метод main должен создавать 6 объектов типа Cat.
3. Программа должна выводить 6 строк с информацией о котах.
4. Строка про дедушку (первая) должна соответствовать условию.
5. Строка про бабушку (вторая) должна соответствовать условию.
6. Строка про папу (третья) должна соответствовать условию.
7. Строка про маму (четвертая) должна соответствовать условию.
8. Строка про сына (пятая) должна соответствовать условию.
9. Строка про дочь (шестая) должна соответствовать условию.
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String granddadName = reader.readLine();
Cat catGranddad = new Cat(granddadName);
String grandMatherName = reader.readLine();
Cat catGrandMather = new Cat(grandMatherName);
String fatherName = reader.readLine();
Cat catFather = new Cat(fatherName,catGranddad);
String MotherName = reader.readLine();
Cat catMother = new Cat(MotherName,catGrandMather);
String sonName = reader.readLine();
Cat catSon = new Cat(sonName,catMother,catFather);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName,catMother,catFather);
System.out.println(catGranddad);
System.out.println(catGrandMather);
System.out.println(catFather);
System.out.println(catMother);
System.out.println(catSon);
System.out.println(catDaughter);
}
public static class Cat {
private String name;
private Cat granDad;
private Cat granMather;
private Cat father;
private Cat mother;
private Cat son;
private Cat daughter;
Cat(String name ) {
this.name = name;
}
Cat(String name, Cat granDad, Cat granMather , Cat father, Cat mother, Cat son, Cat daughter) {
this.name = name;
this.granDad = granDad;
this.granMather = granMather;
this.father = father;
this.mother = mother;
this.son = son;
this.daughter = daughter;
}
@Override
public String toString() {
if (granDad == null)
return "The cat's name is " + name + ", no mother no father ";
if (granMather == null)
return "The cat's name is" + name + ", no mother no father ";
if (father == granDad)
return "The cat's name is" + name + ", no mother father is " + granDad + "" ;
if (mother == granMather)
return "The cat's name is" + name + ", mother is " + granMather + " no father" ;
if (son == mother && son == father)
return "The cat's name is" + name + ", mother is " + mother + " father is " + father + "" ;
if (daughter == mother && daughter == father)
return "The cat's name is" + name + ", mother is " + mother + " father is " + father + "" ;
}
}
}