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

Programming Problem 18.12 hashCode and equals methods for the Pair class with La

ID: 3849450 • Letter: P

Question

Programming Problem 18.12 hashCode and equals methods for the Pair class with LabRat

Provide suitable hashCode and equals methods for the Pair class of Section 17.2 and implement a HashMap class, using a HashSet<Pair<K, V>>.

Complete the following classes in your solution:

import java.util.HashSet; import java.util.Collection; import java.util.Set; public class HashMap<K, V> { private HashSet<Pair<K, V>> set; public HashMap() { . . . } public void put(K key, V value) { . . . } public V get(K key) { . . . } public V remove(K key) { . . . } public Set<K> keySet() { . . . } public int size() { return set.size(); } }

Use the following class as your tester class:

Explanation / Answer

import java.util.HashSet;

import java.util.Collection;

import java.util.Set;

public class HashMap<K, V>

{

   private HashSet<Pair<K, V>> set;

   public HashMap()

   {

      . . .

   }

public void put(K key, V value)

   {

      . . .

   }

   public V get(K key)

   {

      . . .

   }

   public V remove(K key)

   {

      . . .

   }

   public Set<K> keySet()

   {

      . . .

   }

   public int size()

   {

      return set.size();

   }

}