I wrote down the code for the task on Eclipse and it runs as it is just fine. It doesn't even needs the "@override" bit. However when I bring the code here it gives me a different result that does not work. Can ayone help me understand why??
thanks in advance yall are great!
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));
Cat granPa = new Cat(reader.readLine());
Cat granMa = new Cat(reader.readLine());
Cat daddyCat = new Cat(reader.readLine(), granPa);
Cat mommyCat = new Cat(reader.readLine(), granMa, null);
Cat catSon = new Cat(reader.readLine(), daddyCat, mommyCat);
Cat catDaughter = new Cat(reader.readLine(), daddyCat, mommyCat);
System.out.println(granPa);
System.out.println(granMa);
System.out.println(daddyCat);
System.out.println(mommyCat);
System.out.println(catSon);
System.out.println(catDaughter);
}
public static class Cat {
private String name;
private Cat father;
private Cat mother;
Cat(String name){
this.name = name;
}
Cat(String name, Cat mother){
this.name = name;
this.mother = mother;
}
Cat(String name, Cat mother, Cat father){
this.name = name;
this.mother = mother;
this.father = father;
}
@Override
public String toString() {
String catFather = (father == null) ? ", no father": father.name + " is the father";
String catMother = (mother == null) ? ", no mother" : mother + "is the mother";
return "the cat name is " + name + catMother + catFather;
}
}
}