Выдаёт ошибку класса. В общем, совсем непонятно, что именно.
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 grandFatherName = reader.readLine();
Cat grandFather = new Cat(grandFatherName, "gf");
String grandMotherName = reader.readLine();
Cat grandMother = new Cat(grandMotherName, "gm");
String fatherName = reader.readLine();
Cat father = new Cat(fatherName, grandFather, 'f');
String motherName = reader.readLine();
Cat mother = new Cat(motherName, grandMother, 'm');
String sonName = reader.readLine();
Cat son = new Cat(sonName, father, mother, 's');
String daughterName = reader.readLine();
Cat daughter = new Cat(daughterName, father, mother, 'd');
System.out.println(grandFather);
System.out.println(grandMother);
System.out.println(father);
System.out.println(mother);
System.out.println(son);
System.out.println(daughter);
}
public static class Cat {
private String grandFatherName;
private String grandMotherName;
private Cat grandFather;
private Cat grandMother;
private String fatherName;
private String motherName;
private Cat father;
private Cat mother;
private String brotherName;
private String sisterName;
Cat(String grandParent, String literal) {
if(literal.equals("gf")) {
this.grandFatherName = grandParent;
}
else {
this.grandMotherName = grandParent;
}
}
Cat(String parentName, Cat grandParent, char literal) {
if(literal == 'f') {
this.fatherName = parentName;
this.grandFather = grandParent;
}
else {
this.motherName = parentName;
this.grandMother = grandParent;
}
}
Cat(String name, Cat father, Cat mother, char literal) {
if(literal == 's') {
this.brotherName = name;
this.father = father;
this.mother = mother;
}
else {
this.sisterName = name;
this.father = father;
this.mother = mother;
}
}
@Override
public String toString() {
if (grandFatherName != null) {
return ("The cat's name is " + grandFatherName + ", no mother, no father");
}
else if (grandMotherName != null) {
return ("The cat's name is " + grandMotherName + ", no mother, no father");
}
else if (fatherName != null) {
return ("The cat's name is " + fatherName + ", no mother, father is " + grandFather.grandFatherName);
}
else if (motherName != null) {
return ("The cat's name is " + motherName + ", mother is " + grandMother.grandMotherName + ", no father");
}
else if (brotherName != null) {
return ("The cat's name is " + brotherName + ", mother is " + mother.motherName + ", father is " + father.fatherName);
}
else if (sisterName != null) {
return ("The cat's name is " + sisterName + ", mother is " + mother.motherName + ", father is " + father.fatherName);
}
else return "They are not cats!";
}
}
}