public class Solution { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String catGfathername = reader.readLine(); Cat catGfather = new Cat(catGfathername); String gmotherName = reader.readLine(); Cat catGmother = new Cat(gmotherName); String fatherName = reader.readLine(); Cat catFather = new Cat(fatherName, null, catGfather); String motherName = reader.readLine(); Cat catMother = new Cat(motherName, catGmother, null); 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(catGfather); System.out.println(catGmother); 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 momName; private Cat dadName; Cat(String name) { this.name = name; } Cat(String name, Cat momName,Cat dadName ) { this.name = name; this.momName = momName; this.dadName = dadName; } @Override public String toString() { if (dadName == null && momName == null) return "The cat's name is" + name + ", no mother, no father"; else if (momName == null ) return "The cat's name is "+ name+ ", no mother, father is "+ dadName; else if (dadName == null) return "The cat's name is " +name+", mother is " +momName+", no father"; else return "The cat's name is "+name+ ", mother is "+ momName+ ", father is " + dadName; } } }