Почему нельзя передать list.get() при создании об'єкта списка catList. ?
package com.javarush.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.util.*;
/*
Родственные связи кошек
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList <String> list = new ArrayList <String> ();
for (int i = 0; i < 6; i++) {
list.add(reader.readLine());
}
//String gFather = list.get(0);
ArrayList <Cat> catList = new ArrayList <Cat> ();
catList.add(new Cat(list.get(0), null, null));
catList.add(new Cat(list.get(1), null, null));
catList.add(new Cat(list.get(2), null, list.get(0)));
catList.add(new Cat(list.get(3), list.get(1), null));
catList.add(new Cat(list.get(4), list.get(3), list.get(2)));
catList.add(new Cat(list.get(5), list.get(3), list.get(2)));
catList.stream().forEach(System.out::println);
}
public static class Cat {
private String name;
private Cat mother;
private Cat father;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat mother, Cat father) {
this.name = name;
this.mother = mother;
this.father = father;
}
@Override
public String toString() {
if ((mother == null) && (father == null)) {
return "The cat's name is " + name + ", no mother, no father";
} else if ((mother == null) && (father != null)) {
return "The cat's name is " + name + ", mother is " + mother.name + ", no father";
} else if ((mother != null) && (father == null)) {
return "The cat's name is " + name + ", no mother, father is " + father.name;
} else {
return "The cat's name is " + name + ", mother is " + mother.name + ", father is " + father.name;
}
}
}
}