I have no idea how to solve this one. I have tried everything I know and I dont want to cheat. Can someone point me in the right direction?
package com.codegym.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Cat relations
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String grandfatherName = reader.readLine();
Cat catGrandFather = new Cat(grandfatherName);
String grandmotherName = reader.readLine();
Cat catGrandMother = new Cat(grandmotherName);
String fatherName = reader.readLine();
Cat catFather = new Cat(fatherName);
System.out.println(catGrandFather);
System.out.println(catGrandMother);
System.out.println(fatherName);
}
public static class Cat {
private String name;
private Cat grandPa;
private Cat grandMa;
private Cat father;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat grandPa) {
this.name = name;
this.grandPa = grandPa;
}
Cat(String name, Cat grandPa, Cat grandMa){
this.name = name;
this.grandPa = grandPa;
this.grandMa = grandMa;
}
Cat (String name, Cat grandPa, Cat grandMa, Cat father){
this.name = name;
this.grandPa = grandPa;
this.grandMa = grandMa;
this.father = father;
}
@Override
public String toString() {
if (grandPa == null)
return "The cat's name is " + name + ", no mother, no father ";
else
return "The cat's name is " + name + ", no mother, no father ";
}
}
}