Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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 .

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

Java, Programming

  • Category:- Java
  • Reference No.:- M92397906
  • Price:- $15

Priced at Now at $15, Verified Solution

Have any Question?


Related Questions in Java

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As