Уже не знаю что и делать(
package com.javarush.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 grandFaName = reader.readLine();
Cat catGrandFa = new Cat(grandFaName);
String grandMaName = reader.readLine();
Cat catGrandMa = new Cat(grandMaName);
String fatherName = reader.readLine();
Cat catFather = new Cat(fatherName,catGrandFa);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName,catGrandMa);
String brotherName = reader.readLine();
Cat catBrother = new Cat(brotherName,catMother,catFather);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName, catMother,catFather);
System.out.println(catGrandFa);
System.out.println(catGrandMa);
System.out.println(catFather);
System.out.println(catMother);
System.out.println(catBrother);
System.out.println(catDaughter);
}
public static class Cat {
private String name;
private Cat Dad;
private Cat Mom;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat Mom){
this.name=name;
this.Mom=Mom;
}
Cat(String name, Cat Dad, Cat Mom) {
this.name = name;
this.Dad = Dad;
this.Mom = Mom;
}
@Override
public String toString() {
if (Dad == null && Mom == null)
return "The cat's name is " + name + ", no mother, no father ";
else if(Dad == null)
return "The cat's name is " + name + ", mother is " + Mom.name + ", no father ";
else if(Mom == null)
return "The cat's name is " + name + ", no mother, " + " father is "+Dad.name;
else
return "The cat's name is " + name + ", mother is " + Dad.name + ", father is " + Mom.name;
}
}
}
Dad→ dad,Mom→ mom.