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: 3761630 • 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;

  

    public MyHashMap( HashFunction<KeyType> h1, HashFunction<KeyType> h2 )

      { /* You must implement */ }

  

    public int size( )

      { /* You must implement */ }

  

    public void clear( )

      { /* You must implement */ }

  

    public ValueType put( KeyType k, ValueType v )

      { /* You must implement */ }

  

Explanation / Answer

public int size( )
{
return theSet.size( );
}
public void clear( )
{
theSet.clear( );
}
public ValueType put( KeyType key, ValueType value )
{
Map.Entry<KeyType,ValueType> match = theSet.getMatch( makePair( key ) );
if( match != null )
return match.setValue( value );
theSet.add( makePair( key, value ) );
return null;
}

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