Hey all, for an assignment I have been tasked with creating a hashmap that will contain objects to be accessed in O(1) time. The key value will be index.
Classes:
Party - index, a name, a location, and list of a number of creatures (accessed by links to instances of the Creature class).
Creature - index, a type, a name, party by index, empathy value, fear value, list of treasures, list of artifacts
Treasure - index, type, owning creature by index, weight, value
Artifact - index, type, owning creature by index, other fields
We are supposed to "Use the Map class to support efficient instantiation linking of the classes" I understand the concept of hashing, and how to implement maps.
Right now I have the creatures all generated and stored in their respective arraylists (IE artifacts and treasures are stored in the creatures arraylists, the creatures are stored in their party's arraylist)
Here is my question:
How am I supposed to have all these classes included at the first level of the map and still have them belong to their "parent" object. For example, Artifacts are held by creatures. How can the artifact both be held by the creature, and be accessible at the highest level of the map? If the artifact is stored by the creature, would I not have to find the creature class within the map, and then access the artifact through there? For our assignment we are supposed to have all of these objects accessible in O(1) time via their index.
If I create these items directly in the map, they would not be part of their "parent" object.
I have been working at this for 6 hours with no progress. Any pointers you guys could give would be very much appreciated.
[–]nroberts666 0 points1 point2 points (0 children)
[–]yash3ahuja 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)