package com.codegym.task.task06.task0621; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /* Cat relations */ public class Solution { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String grandfather = reader.readLine(); Cat catgrandMother = new Cat(grandfather); String grandmother = reader.readLine(); Cat catgrandfather = new Cat(grandmother); String father = reader.readLine(); Cat catFather = new Cat(father, catgrandMother); String mother = reader.readLine(); Cat catMother = new Cat(mother, catgrandfather); String son = reader.readLine(); Cat catSon = new Cat(son, catMother,catFather); String daughter = reader.readLine(); Cat catdaughter = new Cat(daughter, catMother,catFather); System.out.println(catgrandMother); System.out.println(catgrandfather); 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 parent; private Cat mother; Cat(String name) { this.name = name; } Cat(String name, Cat parent) { this.name = name; this.parent = parent; } Cat(String name, Cat parent,Cat mother) { this.name = name; this.parent = parent; this.mother=mother; } @Override public String toString() { if (parent == null) return "The cat's name is " + name + ", no mother "+", no father "; else if(name.contains("Father Oscar")) return "The cat's name is " + name + ", no mother," + parent.name + " is the father"; else if(name.contains("Mother Missy")) return "The cat's name is " + name + ", " + parent.name+ " is the mother,"+" no father,"; else if(name.contains("Son Simba")) return "The cat's name is " + name + ", " + parent.name + " is the mother,"+ mother.name+ " is the father"; else return "The cat's name is " + name + ", " + parent.name + " is the mother,"+ mother.name+ " is the father"; } } }