package com.javarush.task.task06.task0621; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /* Родственные связи кошек */ public class Solution { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String grandfather = reader.readLine(); Cat catgrandfather = new Cat(grandfather); String grandmother = reader.readLine(); Cat catgrandmother = new Cat(grandmother); String father = reader.readLine(); Cat catfather = new Cat(father); String mother = reader.readLine(); Cat catMother = new Cat(mother); String son = reader.readLine(); Cat catson = new Cat(son); String daughter = reader.readLine(); Cat catDaughter = new Cat(daughter); System.out.println(catgrandfather); System.out.println(catgrandmother); 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 catfather; private Cat catMother; Cat(String name) { this.name = name; } Cat(String name, String father, String mother) { this.name = name; Cat catfather = father; Cat catMother=mother; } @Override public String toString() { if (catMother==null && catfather==null) { return "Cat name is " + name + ", no mother "+ "no father";} if (catMother==null && catfather!=null){ return "Cat name is " + name + ", no mother "+", father is"+ catfather;} if (catMother!=null && catfather==null) return "Cat name is " + name + ", mother is " + catMother; if (catMother!=null && catfather!=null){ return "Cat name is " + name + ", mother is " + catMother+ ", father is"+ catfather;} return name; } } }