Reference no: EM131589192
Generic data structures
It is possible to use generic types to implement classes or interfaces. These can be reused in many contexts, with parameterized types. Remember the interface Comparable! By using the generic type, we make sure to keep the compiler validation.
Implement the interface Map
Define the interface Map. A class that realizes Map has to save the key-value association. In our case, we need a Map to contain identical keys, in which case the method get, put, replace, and remove will refer to the association containing this key that is the further left (the last). Map is a generic class with two types of parameters, K and V, where K is the type of the Key and V is the type of the values. A Map has the following methods:
V get(K key) : Returns the leftmost value associated to the key specified in the parameter.
boolean contains(K key) : Returns true if there is an association for the key specified in the parameter
void put(K key, V value) : Creates a new key-value association
void replace(K key, V value) : Replaces the value of the leftmost occurrence of the association for the specified key
V remove(K key) : Removes the leftmost occurrence of the specified key and returns the value that was associated to this key
Note that no parameter can be null in any of these methods
Implement the class Dictionary
Dictionary keeps track of String-Integer associations (key-value).
The Dictionary class implements the interface Map <String,Integer >.
It uses an array (first instance variable) to store each association. The elements in this array are of type Pair , a class that will be public. A Pair type object must store an association, "key" and "value" of type String and Integer respectively. Note this is an alternative solution until nested classes are taught in class.
You must treat your array of items as a stack. So the bottom of your stack will be element 0, while the top of the stack will be the non-null element at the highest position. Use a counter (second instance variable) that will tell you how many items are in your table.
Finally, because the Dictionary class stores an arbitrarily large number of associations, you will need to use the dynamic table technique (as shown in part 1). The initial size of the array will be 10, while its increment will be 5 whenever the array is full. These two values will be treated as constants.
You clearly need to implement all methods of the interface. Do not forget to consider that the leftmost association (element of type Pair) will always be the top most of the stack! You will therefore have to go through your table in the opposite direction.
Add a toString() method that prints your table elements from last to first (top of stack to bottom of stack).
DictionaryTest.java includes a series of tests for your implementation.
Attachment:- DictionaryTest.rar
In the news-alibaba ipo sets record
: On September 18, 2014, the Chinese e-commerce company completed the largest initial public offering (IPO) in history, raising more than $21 billion.
|
What is the proper adjusted cash balance per bank
: Jim Parkus is unable to reconcile the bank balance at January 31. Jim's reconciliation is shown here. What is the proper adjusted cash balance per bank
|
Describe how to properly document bloodstain pattern
: Select two different types of bloodstain patterns discussed in the Saferstein book describe each pattern, explain what causes each pattern
|
Concepts of absolute and comparative advantage
: Explain to someone with no economic knowledge the concepts of Absolute and Comparative Advantage and why each makes a valid argument for international trade.
|
Implement the interface map
: Define the interface Map. A class that realizes Map has to save the key-value association. In our case, we need a Map to contain identical keys
|
Absence of additional income or health services
: What measures can families take, even in the absence of additional income or health services, to keep their children healthy? Explain
|
What is the slope of the budget constraint
: Draw Marie's budget constraint with pies on the horizontal axis and magazines on the vertical axis. What is the slope of the budget constraint?
|
Simulate a game of tic tac toe
: Classes as specified in the UML diagram. You may add other methods if needed, however, all the methods and the variables indicated in the UML diagram
|
Prepare a consolidated worksheet for brooks and chandler
: Show how Brooks determined the following account balances Gain on bargain purchase. Prepare a December 31, 2015, consolidated worksheet for Brooks and Chandler
|