public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        System.out.println("введите имя бабушки");
        String grandmaName = reader.readLine();
        Cat grandma = new Cat(grandmaName, null, null);

        System.out.println("введите имя дедушки");
        String grandpaName = reader.readLine();
        Cat grandpa = new Cat(grandpaName, null, null);

        System.out.println("введите имя отца");
        String fatherName = reader.readLine();
        Cat father = new Cat(fatherName, null, grandpa);

        System.out.println("введите имя мамы");
        String motherName = reader.readLine();
        Cat catMother = new Cat(motherName, grandma, null);

        System.out.println("введите имя дочери");
        String daughterName = reader.readLine();
        Cat catDaughter = new Cat(daughterName, catMother, father);

        System.out.println("введите имя сына");
        String sonName = reader.readLine();
        Cat son = new Cat(sonName, catMother, father);

        System.out.println(grandma);
        System.out.println(grandpa);
        System.out.println(father);
        System.out.println(catMother);
        System.out.println(catDaughter);
        System.out.println(son);
    }

    public static class Cat {
        private String name;
        private Cat firstParent;
        private Cat secondParent;

        Cat(String name) {
            this.name = name;
        }

        Cat(String name, Cat firstParent, Cat secondParent) {
            this.name = name;
            this.firstParent = firstParent;
            this.secondParent = secondParent;
        }

        @Override
        public String toString() {
            if (firstParent == null & secondParent == null & name!=null)
                return "The cat's name is " + name + ", no mother, no father";
            else if (firstParent == null & name!=null & secondParent!=null)
                return "The cat's name is " + name + ", no mother, father is " + secondParent;
            else if (secondParent == null & firstParent!=null & name!= null)
                return "The cat's name is " + name + ", mother is " + firstParent + ", no father";
            else if (secondParent!= null & firstParent!= null & name!= null)
                return "The cat's name is " + name + ", mother is " + firstParent + ", father is " + secondParent;
            else return toString();
        }
    }

}