I got result needed and I consider it to be solved, now why codegym doesn't like my code, I want to get a credit for a time spent, and few hints on what results should look like in a future would be appreciated. I like to experiment but it looks like there certain template I should be following to get codegym to accept my code. Anyway, thanx for any help it would be most welcome...
package com.codegym.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Cat relations
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String name;
Cat mother = null;
Cat father = null;
ArrayList<Cat> cats = new ArrayList<>(6);
for (int i = 0; i < 6; i++) {
name = reader.readLine();
if (name.contains("Grandfather")) {
cats.add(father = new Cat(name, null, null));
}
if (name.contains("Grandmother")) {
cats.add( mother = new Cat(name, null, null));
}
if (name.contains("Father")){
cats.add(father = new Cat(name, father, null));
}
if (name.contains("Mother")){
cats.add(mother = new Cat(name, null, mother));
}
if (name.contains("Son") || name.contains("Daughter")){
cats.add(new Cat(name, father, mother));
}
}
for (int i = 0; i < 6; i++) {
System.out.println(cats.get(i).toString());
}
}
public static class Cat {
private String name;
private Cat father = null;
private Cat mother = null;
//private Cat parent;
Cat(String name, Cat father, Cat mother) {
this.name = name;
this.father = father;
this.mother = mother;
}
@Override
public String toString() {
String msg = "The cat's name is " + name;
if(mother == null) msg += ", no mother";
else msg += (" " + mother.name + " is the mother");
if (father == null) msg += ", no father";
else msg += (" " + father.name + " is the father");
return msg;
}
}
}