Question: How do I write a put method in Array Dictionary. What is the contructor going to be like? package datastructures.concrete.dictionaries; import java.lang.reflect.Array; import datastructures.interfaces.IDictionary; import

How do I write a put method in Array Dictionary.

What is the contructor going to be like?

package datastructures.concrete.dictionaries;

import java.lang.reflect.Array;

import datastructures.interfaces.IDictionary; import misc.exceptions.NoSuchKeyException; import misc.exceptions.NotYetImplementedException;

/** * See IDictionary for more details on what this class should do */ public class ArrayDictionary implements IDictionary { // You may not change or rename this field: we will be inspecting // it using our private tests. private Pair[] pairs;

// You're encouraged to add extra fields (and helper methods) though!

public ArrayDictionary() { @SuppressWarnings("unchecked") Pair[] pairs = (Pair[]) new Pair[100]; }

/** * This method will return a new, empty array of the given size * that can contain Pair objects. * * Note that each element in the array will initially be null. */ @SuppressWarnings("unchecked") private Pair[] makeArrayOfPairs(int arraySize) { // It turns out that creating arrays of generic objects in Java // is complicated due to something known as 'type erasure'. // // We've given you this helper method to help simplify this part of // your assignment. Use this helper method as appropriate when // implementing the rest of this class. // // You are not required to understand how this method works, what // type erasure is, or how arrays and generics interact. Do not // modify this method in any way. return (Pair[]) (new Pair[arraySize]);

}

@Override public void put(K key, V value) { }

How do I write a put method in Array Dictionary. What is

Part 1d: Implement ArrayDictionary Task: complete the ArrayDictionary class Your ArrayDictionary class will internally keep track of its key-value pairs by using an array containing Pair objects new ArrayDictionary>0; 1Dictionary String, Integer> foo 2foo.put"a", 11) 3foo.put"b", 22); foo put" 33); Your internal array should look like the following Contents: Pair("a", 11)Pair("b", 11) Pair("c", 11) 2 Now, suppose the user inserted a few more ke ys 1foo put'd,44) 2 foo.delete(b") 3foo.put"a", 55) Your internal array should now look like the below. Notice that we've updated the old key-value pair for "a" to store the new value We've also removed the key-value pair for "b Contents Pair("a", 55) Pair("c", 33)"d", 44) 2 This means you will need to scan through the internal array when retrieving, inserting, or deleting elements. If your array is full and the user inserts a new key, create a new array double the size of the old one and copy over the old elements Once completed, the design and logic of your ArrayDictionary should feel very similar to the ArraylntList objects you previously studied in CSE 143 Part 1d: Implement ArrayDictionary Task: complete the ArrayDictionary class Your ArrayDictionary class will internally keep track of its key-value pairs by using an array containing Pair objects new ArrayDictionary>0; 1Dictionary String, Integer> foo 2foo.put"a", 11) 3foo.put"b", 22); foo put" 33); Your internal array should look like the following Contents: Pair("a", 11)Pair("b", 11) Pair("c", 11) 2 Now, suppose the user inserted a few more ke ys 1foo put'd,44) 2 foo.delete(b") 3foo.put"a", 55) Your internal array should now look like the below. Notice that we've updated the old key-value pair for "a" to store the new value We've also removed the key-value pair for "b Contents Pair("a", 55) Pair("c", 33)"d", 44) 2 This means you will need to scan through the internal array when retrieving, inserting, or deleting elements. If your array is full and the user inserts a new key, create a new array double the size of the old one and copy over the old elements Once completed, the design and logic of your ArrayDictionary should feel very similar to the ArraylntList objects you previously studied in CSE 143

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!