Please implement in Java implement a keyed bag in which the items to be stored are strings (perhaps people’s names) and the keys are numbers (perhaps Social Security or other identification numbers). So, the in- sertion method has this specification: public void insert (String entry, int key); // Precondition: size( ) < CAPACITY, and the // bag does not yet contain any item // with the given key. // Postcondition: A new copy of entry has // been added to the bag, with the given key. When the programmer wants to remove or retrieve an item from a keyed bag, the key of the item must be specified rather than the item itself. The keyed bag should also have a boolean method that can be used to determine whether the bag has an item with a specified key. In a keyed bag, the pro- grammer using the class specifies a particular key when an item is inserted. Here’s an implementation idea: A keyed bag can have two private arrays, one that holds the string data and one that holds the corresponding keys. The data at location data[i] has a key that is stored in key[i].
Please implement in Java
implement a keyed bag in which the items to be stored are strings (perhaps people’s names) and the keys are numbers (perhaps Social Security or other identification numbers). So, the in- sertion method has this specification:
public void insert
(String entry, int key);
// Precondition: size( ) < CAPACITY, and the // bag does not yet contain any item
// with the given key.
// Postcondition: A new copy of entry has
// been added to the bag, with the given key.
When the programmer wants to remove or retrieve an item from a keyed bag, the key of the item must be specified rather than the item itself. The keyed bag should also have a boolean method that can be used to determine whether the bag has an item with a specified key.
In a keyed bag, the pro- grammer using the class specifies a particular key when an item is inserted.
Here’s an implementation idea: A keyed bag can have two private arrays, one that holds the string data and one that holds the corresponding keys. The data at location data[i] has a key that is stored in key[i].
Given data,
implement a keyed bag in which the items to be stored are strings (perhaps people’s names) and the keys are numbers (perhaps Social Security or other identification numbers). So, the insertion method has this specification:
public void insert
(String entry, int key);
// Precondition: size( ) < CAPACITY, and the // bag does not yet contain any item
// with the given key.
// Postcondition: A new copy of the entry has
// been added to the bag, with the given key.
When the programmer wants to remove or retrieve an item from a keyed bag, the key of the item must be specified rather than the item itself. The keyed bag should also have a boolean method that can be used to determine whether the bag has an item with a specified key.
In a keyed bag, the programmer using the class specifies a particular key when an item is inserted.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 6 images