This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Hey guys, I was wondering, I have to write a code for a HashMap that maps two words to essentially one meaning. For example, I have to make sure that if someone types crash, it will generate the same response as crashes, how would I map these two together?
Don’t start by assuming a HashMap is the answer. It might not be. Write down with pencil and paper (and eraser) exactly how you think you ought to solve that problem. That will enable you to go from concept to code.
I suspect the point of the assignment is to use hashing.
Given that as the case:
If crash hashes to the same value as crashes, use that (the hash) as your key and the meaning as your value. Hash crash and crashes from one thing that you know they share: the meaning of the word.
A little bit of circular reasoning but if the only thing this accomplishes is to get you thinking that's at least a step in the right direction.
And while you're overriding hashCode(), you should probably override equals() as well...just as a complete side note.
Everything is theoretically impossible, until it is done. ~Robert A. Heinlein
Agree with Campbell. Until you know how you define when two words are equivalent, it's pointless trying to worry about what data structures to use. What you've described so far is potentially a massive task (and probably impossible without a complete dictionary). If it's an assignment I expect something a bit simpler is intended.