Hashtable stores information in the form of a key and value.. If i want to associate different marks of assignments to different names, it will have variables like studentName, assignmentNo and mark. Kindly advise how do i structure the hashtable to store and retrieve the correct marks belonging to a certain assignmentNo and certain studentName. Would appreciate if examples is provided... thank you in advance... Say every student have 3 assignments.
Well, there are many different ways to do this. One way would be to have an array of all of the assignments as the hash table value, so that the student's name would be associated with a double for instance, and the index of the array would be the assignment number. Alternatively, you can use another hashtable or any other ADT. [ June 21, 2004: Message edited by: Darin Niard ]
The better approach would be to create an object that has the internal structure you'd like to keep for all of this information. What is the association between a student and their grades? You might decide that a student should have a class history, for example. So you write a Class object that represents a single class, has properties like professor, title, department, etc. Then an array representing the class history, each item of which might be a ClassHistoryItem, which is a reference to the class, the grade earned, the term in which the class was taken.
This is just a very rough first cut, but you can see that how you structure information is what makes OOP powerful:
Now you can have a HashMap (don't use Hashtable anymore, that's an old class from the days of the JDK 1.1) that stores student objects and associates them with a student id, or their name, or whatever info you want to use as the key.