Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Java, fill the ¨you must implement¨ spots... import java.util.Map; import

ID: 3761640 • Letter: U

Question

Using Java, fill the ¨you must implement¨ spots...

import java.util.Map;

import java.util.Iterator;

public interface HashFunction<AnyType>

{

    int hashCode( AnyType x );

}

public class MyHashMap<KeyType,ValueType> implements Iterable<Map.Entry<KeyType,ValueType>>

{

    private HashFunction<KeyType> hash1;

    private HashFunction<KeyType> hash2;

private static class Node<KeyType,ValueType>

    {

        Node( KeyType k, ValueType v, Node<KeyType,ValueType> n )

        { key = k; value = v; next = n; }

      

        public String toString( )

        { return key + "=" + value; }

      

        KeyType key;

        ValueType value;

        Node<KeyType,ValueType> next;

    }

  

    public int [ ] getLengths( )

      { /* You must implement */ }

    private static final int DEFAULT_ARRAY_SIZE = 11;

  

    private Node<KeyType,ValueType> [ ] arr = null;

    private int theSize = 0;

}

Explanation / Answer

public static <A, B, C> Map<A, C> transitise(Map<A, B> aToB, Map<B, C> bToC)

{

HashMap<A, C> map = new HashMap<A, C>(aToB.size() * 2);

for (Map.Entry<A, B> abEntry : aToB.entrySet())

{

map.put(abEntry.getKey(), bToC.get(abEntry.getValue()));

}

return map;

}

public static void main(String[] args)

{

HashMap<String, Integer> nameToNumber = new HashMap<String, Integer>();

nameToNumber.put("Anna", 12345);

nameToNumber.put("James", 444);

HashMap<Integer, Point> numberToPosition = new HashMap<Integer, Point>();

numberToPosition.put(12345, new Point(3, 3));

numberToPosition.put(444, new Point(1, 55));

for (Map.Entry<String, Point> nTP :

transitise(nameToNumber, numberToPosition).entrySet())

{

System.out.println(nTP.getKey() + " -> " +

nTP.getValue().x + "/" + nTP.getValue().y);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote