Why I stuck 6 Object , when I created 6 Objs Completed
package com.codegym.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Cat relations
The cat's name is Grandfather Tiger, no mother, no father
The cat's name is Grandmother Puss, no mother, no father
The cat's name is Father Oscar, no mother, Grandfather Tiger is the father
The cat's name is Mother Missy, Grandmother Puss is the mother, no father
The cat's name is Son Simba, Mother Missy is the mother, Father Oscar is the father
The cat's name is Daughter Coco, Mother Missy is the mother, Father Oscar is the father
Grandfather Tiger
Grandmother Puss
Father Oscar
Mother Missy
Son Simba
Daughter Coco
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String grandfatherName = reader.readLine();
OldCat catgrandfa = new OldCat(grandfatherName);
String grandMotherName = reader.readLine();
OldCat catgrandma = new OldCat(grandMotherName);
String fatherName = reader.readLine();
OldCat catfather = new OldCat(fatherName,grandfatherName);
String motherName = reader.readLine();
OldCat catmother = new OldCat(motherName,null,grandMotherName);
String sonName = reader.readLine();
OldCat catson = new OldCat(sonName,fatherName,motherName);
String daughterName = reader.readLine();
OldCat catdaughter = new OldCat(daughterName,fatherName,motherName);
System.out.println(catgrandfa);
System.out.println(catgrandma);
System.out.println(catfather);
System.out.println(catmother);
System.out.println(catson);
System.out.println(catdaughter);
}
public static class OldCat{
private String name;
private String father;
private String mother;
//private OldCat c_father;
//private OldCat c_mother;
OldCat(String name){
this.name = name;
}
OldCat(String name,String father){
this.name = name;
this.father = father;
}
OldCat(String name,String father,String mother){
this.name = name;
this.father = father;
this.mother = mother;
}
@Override
public String toString() {
if (father == null && mother == null) {
return "The cat's name is " + name + ", no mother, no father";
} else if (father != null && mother == null) {
return "The cat's name is " + name + ", no mother, " + father + " is the father";
} else if (father == null && mother != null) {
return "The cat's name is " + name + ", " + mother + " is the mother, no father";
} else {
return "The cat's name is "+name+", "+mother+" is the mother, "+father+" is the father";
}
}
}
}