не проходит проверку хотя вроде все работает правильно. намекните что ему не нравится.
package com.javarush.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Родственные связи кошек
*/
public class Solution {
public static ArrayList<Cat> cats = new ArrayList<>();
public static void main(String[] args) throws IOException {
String catBuffer;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
catBuffer = reader.readLine();
cats.add(new Cat(catBuffer));
catBuffer = reader.readLine();
cats.add(new Cat(catBuffer));
catBuffer = reader.readLine();
cats.add(new Cat(catBuffer,null,cats.get(1)));
catBuffer = reader.readLine();
cats.add(new Cat(catBuffer,cats.get(0),null));
catBuffer = reader.readLine();
cats.add(new Cat(catBuffer,cats.get(3),cats.get(2)));
catBuffer = reader.readLine();
cats.add(new Cat(catBuffer,cats.get(3),cats.get(2)));
for (Cat cat: cats){
System.out.println(cat.toString());
}
// catBuffer = reader.readLine();
// cats.add(new Cat(catBuffer));
// String daughterName = reader.readLine();
// Cat catDaughter = new Cat(daughterName, catMother);
//Cat cat1 = cats.get(1);
// System.out.println(cat1.name);
//System.out.println(catDaughter);
}
public static class Cat {
public String name;
public Cat mother;
public Cat father;
Cat(String name) {
this.name = name;
}
// Cat(String name, Cat mother) {
// this.name = name;
// this.mother = mother;
// }
Cat(String name, Cat mother, Cat father){
this .name =name;
if(mother == null & father != null ){
this.mother = mother ;
this.father = cats.get(0);
} else if (father == null & mother != null){
this.father = father;
this.mother = cats.get(1);
}else {
this.mother = mother;
this.father = father;
}
}
public String toString() {
if (mother == null & father!=null) return "The cat's name is " + name + ", no mother" + ", father is " + father.name;
else if (father ==null & mother!=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" + ", no father ";
return "The cat's name is " + name + ", mother is " + mother.name + ", father is " + father.name;
}
}
}