Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Description: A \'Dictionary\' is a data structure like an array, but instead of

ID: 3569157 • Letter: D

Question

Description:

A 'Dictionary' is a data structure like an array, but instead of the values being indexed by keys running from 0 to (length - 1), instead the keys can be arbitrary. Consider a dictionary of student grades. We might have the following key/value pairs:

key   value

Barry   81

Caroline 93

Jennifer 80

Katherine   94

Mary 77

--------------------------------------------------------------------------------------------

Here, a student's grade (an Integer) can be looked up using their name (a String). Using Java's generic syntax, we can imagine this would be stored in a dictionary with the following type:

Dictionary<String, Integer>

------------------------------------------------------------------------------------------

Objective:

Write a Java interface for a generic Dictionary type. You must give declarations (but not definitions) for the following methods (NOTE: the ??? must be replaced with the proper generic types):

* public ??? add(??? key, ??? value) - This method will associate a given value with the specified key

* public ??? get(??? key) - This method will retrieve the value for a specified key

-------------------------------------------------------------------------------------

Hint:

If you are having trouble with the class header, you should use the javadoc for Map as a reference.

**Upload Dictionary.java to the dropbox**

Explanation / Answer

//As the question specifies, the following interface is the generic (can be used for any data types) that is expected

//Please save the following contents in Dictionary.java

public interface Dictionary<K, V> {
   public V add(K key, V value);
   public V get(K key);
}