I'm just learning Java, so please bear with my ignorance. I have a feeling (hope) that this question has a very simple answer, just one that is evading me at the moment.
For our assignment, we have to write a boolean function that will take a given elephant, "e" (the program we're writing is used to store data about elephants) and return true if this elephant is e's mother, and e isn't null.
We have also previously written a getMother() function that will return the elephant's mother.
As such, I need to ensure e isn't null, and verify that e.getMother() returns the name of the elephant calling the function. Sounded easy enough, but several, several hours later I'm no closer to figuring out how to do that.
For example:
Elephant mom = new Elephant("Mom", 1990, 2, 'f');
Elephant dad = new Elephant("Dad", 1990, 10, 'm');
Elephant kid = new Elephant ("Joey", 1995, 7, 'M', 5, mom, dad);
mom.isMotherOf(kid); //Needs to return true
e.getMother will return the name of e's mother, but I don't know how to compare that to whatever elephant is calling the function
boolean isMotherOf(Elephant e) {
return ( e != null && e.getMother() == /* ?????? */)
}
Fot context, a copy of the assignemnt can be found here.
If anyone could point me in the right direction, it would greatly be appreciated. I've already spent more time on his than I did every project up to this point. Let me know if I need to clarify anything, or provide any of my previous code.