![](https://cdn.javarush.com/images/system/d15b5f0e-4606-4689-8e2f-c7313c83cf3f/1024.jpeg)
List<Cat> cats = new ArrayList<>();
for (int i = 0; i < 6; i++) {
String nam = reader.readLine();
Cat cat = new Cat(nam);
cats.add(cat);
}
package com.javarush.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Родственные связи кошек
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
List<Cat> cats = new ArrayList<>();
for (int i = 0; i < 6; i++) {
String nam = reader.readLine();
Cat cat = new Cat(nam);
cats.add(cat);
}
cats.get(2).father = cats.get(0);
cats.get(3).mother = cats.get(1);
cats.get(4).father = cats.get(2); cats.get(4).mother = cats.get(3);
cats.get(5).father = cats.get(2); cats.get(5).mother = cats.get(3);
for (Cat cat : cats) {
System.out.println(cat);
}
}
public static class Cat {
private String name;
private Cat father;
private Cat mother;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat mother) {
this.name = name;
this.mother = mother;
}
Cat(Cat father, String name ) {
this.name = name;
this.father = father;
}
Cat(String name, Cat mother, Cat father) {
this.name = name;
this.mother = mother;
this.father = father;
}
@Override
public String toString() {
String mother, father;
if (this.mother == null) mother = "no mother";
else mother = "mother is " + this.mother.name;
if (this.father == null) father = "no father";
else father = "father is " + this.father.name;
return "The cat's name is " + this.name + ", " + mother + ", " + father;
}
}
}