Can someone provide me with the right solution? Thanks
package fr.codegym.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Relations avec les chats
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String nomGrPere = reader.readLine();
Chat GrPereChat = new Chat(nomGrPere,null, (Chat) null);
String nomGrMere = reader.readLine();
Chat GrMereChat = new Chat(nomGrMere,null, (Chat) null);
String nomPere = reader.readLine();
Chat pereChat = new Chat(nomPere, (Chat) null, nomGrPere);
String nomMere = reader.readLine();
Chat mereChat = new Chat(nomMere, nomGrMere,null);
String nomFils = reader.readLine();
Chat filsChat = new Chat(nomFils, nomMere, nomPere);
String nomFille = reader.readLine();
Chat filleChat = new Chat(nomFille, nomMere, nomPere);
System.out.println(GrPereChat);
System.out.println(GrMereChat);
System.out.println(pereChat);
System.out.println(mereChat);
System.out.println(filsChat);
System.out.println(filleChat);
}
public static class Chat {
private String nom;
private Chat pere;
private Chat mere;
private String nomPere;
private String nomFils;
private String nomMere;
private Chat fille;
Chat(String nom) {
this.nom = nom;
}
Chat(String nom, Chat fille, Chat pere) {
this.nom = nom;
this.fille = fille;
this.pere = pere;
}
Chat(String nomPere, Chat mere, String nomGrPere) {
this.nomPere=nomPere;
this.mere=mere;
}
Chat(String nomFils, String nomMere, String nomPere) {
this.nomFils=nomFils;
this.nomMere=nomMere;
this.nomPere=nomPere;
}
@Override
public String toString() {
String s="Le nom du chat est " + this.nom+",";
if (mere == null && pere == null)
s += " pas de mère, pas de père";
else if (mere != null && pere == null)
s += mere.nom + " est sa mère, pas de père";
else if (mere == null)
s += " pas de mère, " + pere.nom + " est son père";
return s;
}
}
}