Не понимаю, не могу одуплить как через один класс создать все родственные связи. В текущем варианте верно всё кроме 6 объектов класса кэт.
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 dedName = reader.readLine();
Cat2 catDed = new Cat2(dedName);
String babkaName = reader.readLine();
Cat catBabka = new Cat(babkaName);
String fatherName = reader.readLine();
Cat2 catFather = new Cat2(fatherName, catDed);
Catchild catFather2 = new Catchild(fatherName);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName, catBabka);
Catchild catMother2 = new Catchild(motherName);
String dochName = reader.readLine();
Catchild catDoch = new Catchild(dochName, catMother2, catFather2);
String sonName = reader.readLine();
Catchild catSon = new Catchild(sonName, catMother2, catFather2);
System.out.println(catDed);
System.out.println(catBabka);
System.out.println(catFather);
System.out.println(catMother);
System.out.println(catDoch);
System.out.println(catSon);
}
public static class Cat {
private String name;
private Cat parent;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat parent) {
this.name = name;
this.parent = parent;
}
@Override
public String toString() {
if (parent == null)
return "The cat's name is " + name + ", no mother " + ", no father ";
else
return "The cat's name is " + name + ", mother is " + parent.name + ", no father ";
}
}
public static class Cat2 {
private String name;
private Cat2 parent;
Cat2(String name) {
this.name = name;
}
Cat2(String name, Cat2 parent) {
this.name = name;
this.parent = parent;
}
@Override
public String toString() {
if (parent == null)
return "The cat's name is " + name + ", no mother " + ", no father ";
else
return "The cat's name is " + name + ", no mother" + ", father is " + parent.name;
}
}
public static class Catchild {
private String name;
private Catchild parent;
private Catchild parent2;
Catchild(String name) {
this.name = name;
}
Catchild(String name, Catchild parent, Catchild parent2) {
this.name = name;
this.parent = parent;
this.parent2 = parent2;
}
@Override
public String toString() {
return "The cat's name is " + name + ", mother is " + parent.name + ", father is " + parent2.name;
}
}
}