Implement the interface map

Assignment Help JAVA Programming
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

Reference no: EM131589192

Questions Cloud

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

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd