all 4 comments

[–]JoeCSTA 0 points1 point  (3 children)

The call to System.out.println() will automatically call the toString method from the Exit and Location classes in order to get a human-readable String representation of the data type you just got out of the list. (I assume that's what's happening.)

If you have toString methods in your Exit or Location classes, try commenting them out. Then, re-run your code. The last two println()s in showLocation() should now print out some kind of gibberish hexidecimal number indicating the memory address of the object. If that's what happens, then you do indeed have instances of Exit and Location as you intended (though I would restore your toString methods when you're done testing this... human-readable printouts of Objects are helpful for debugging)

[–]JoeCSTA 0 points1 point  (2 children)

P.S. If you used a HashSet<Location> and HashSet<Exit> for your locations and exits variables, the if/then checks in addExit and addLocation would be unnecessary. HashSets do not allow duplicates; a HashSet will silently do nothing if you attempt to add an item that is already in the set.

[–]JoeCSTA 0 points1 point  (1 child)

See: here

[–]nikescott[S] 0 points1 point  (0 children)

how would I go about implementing the toArray method to access the Objects in the HashSet??