What kind of format is this? Output the third, fifth and sixth lines are not right. What's wrong with me?
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 Name6 = reader.readLine();
Cat cat6 = new Cat(Name6);
String Name5 = reader.readLine();
Cat cat5 = new Cat(Name5);
String Name4 = reader.readLine();
Cat cat4 = new Cat(Name4,null,cat6);
String Name3 = reader.readLine();
Cat cat3 = new Cat(Name3,cat5,null);
String Name2 = reader.readLine();
Cat cat2 = new Cat(Name2,cat3,cat4);
String Name1 = reader.readLine();
Cat cat1 = new Cat(Name1,cat3,cat4);
System.out.println(cat6);
System.out.println(cat5);
System.out.println(cat4);
System.out.println(cat3);
System.out.println(cat2);
System.out.println(cat1);
}
public static class Cat {
private String name;
private Cat parent;
private Cat father;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat parent) {
this.name = name;
this.parent = parent;
}
Cat(String name, Cat parent,Cat father) {
this.name = name;
this.parent = parent;
this.father = father;
}
@Override
public String toString() {
if (parent == null&father==null)
return "猫的名字为" + name + ",无母亲,无父亲";
else if (father==null)
return "猫的名字为" + name + "," + parent.name + "是母亲,无父亲";
else if (parent==null)
return "猫的名字为" + name + ",无母亲 ,"+father.name+"是父亲";
else
return "猫的名字为" + name + "," + parent.name + "是母亲 ,"+father.name+"是父亲";
}
}
}