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

  Write an inner class called randomcolorlistener

Write an inner class called RandomColorListener to implement theActionListener interface and to listen to the JButton in the SOUTH region.

  Java swing components and file processing

Java Swing Components and File Processing, Write a program named GuessGame.java that plays the game "guess the number" as follows. Your program chooses the number to be guessed by selecting an integer at random in the range 1-1000. The program then..

  Write a program that converts date formats

Write a program that prompts the user to input an integer between 0 and 35. If the number is less than or equal to 9, the program should output the number; otherwise, it should output A for 10, B for 11, C for 12,..., Z for 35. (Hint: use the case..

  Design a program in pseudocode

Design a program in pseudocode that solves this problem. You are required to generate only the pseudocode - No charting or analysis section is required, but you may have to incorporate the bubble sort algorithm to determine the minimum and maximum..

  Implement the scan, c_scan, and look disk scheduling algo

The code must have a separate method for each scheduling algorithm and they all have to be called from the main() method.

  Display a welcome message to your user

Write a one screen description of your initial reactions to Java. Reactions may be both positive and negative. At the end of this module you will be asked to write a reply to these initial reactions.

  Define render a model scene in java

Render a Model Scene in Java - Imagine you are prototyping animation for a Jurassic Park Movie

  1 what makes a program easy to modify2 describe the order

1. what makes a program easy to modify?2. describe the order of magnitude of the following code section using bigo

  Design a superclass called shape that contains two functions

Design a superclass called Shape that contains two functions-getArea() and getInput(). The getArea and getInput functions in the Shape class will simply return 0.

  App that allows the user to enter a series of numbers

Write an app that allows the user to enter a series of numbers and manipulate them. The app should provide users with the option of adding or multiplying the numbers.

  A client or server prepare to use udp in a java application

How does a client or server prepare to use UDP in a Java application? Are there any differences in what the client does and what the server does?

  Write a program to compute personal income tax

write a program to compute personal income tax. Your program should prompt the user to enter the filing status and taxable income and compute the tax

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