三五六行一直错误 怎么解决?
package zh.codegym.task.task06.task0621;
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 grandpaName = reader.readLine();
Cat grandpa = new Cat(grandpaName);
String grandmoName = reader.readLine();
Cat grandmo = new Cat(grandmoName);
String fatherName = reader.readLine();
Cat father = new Cat(fatherName, null, grandpa);
String motherName = reader.readLine();
Cat mother = new Cat(motherName, grandmo, null);
String sonName = reader.readLine();
Cat son = new Cat(sonName, mother, father);
String daughterName = reader.readLine();
Cat daughter = new Cat(daughterName, mother, father);
System.out.println(grandpa);
System.out.println(grandmo);
System.out.println(father);
System.out.println(mother);
System.out.println(son);
System.out.println(daughter);
}
public static class Cat {
private String name;
private Cat fa;
private Cat mo;
private Object mother;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat mo, Cat fa) {
this.name = name;
this.mo = mo;
this.fa = fa;
}
@Override
public String toString() {
if (mo == null && fa == null)
return "猫的名字为" + name + ", 无母亲, 无父亲";
else if (mo == null)
return "猫的名字为" + name + ", 无母亲," + fa.name + " 是父亲";
else if (fa == null)
return "猫的名字为" + name + "," + mo.name + " 是母亲, 无父亲";
else
return "猫的名字为" + name + ", " + mo.name + " 是母亲, " + fa.name + " 是父亲";
}
}
}