Produce ArrayMapList and it (implements the MapInterface.java) Here is everything that is needed. The goal is to
Fantastic news! We've Found the answer you've been seeking!
Question:
Produce ArrayMapList and it (implements the MapInterface.java)
Here is everything that is needed. The goal is to use produce an array list map that implements the map interface and works with the tester
import java.util.Collection; import java.util.Set; /** * @author: * */ public interface MapInterface { /** * If the given key is not already in the map, adds the * key-value pair to the map. Otherwise, updates the old * value of the existing key to the specified value. * @param key the key * @param value the value to be stored in the map with the key * @return null if the key was not already in the map, or * the old value associated with the key if the key was already in the map */ public V put(K key, V value); /** * Gets the value from the map that is associated with the given key * @param key the key * @return the value associated with the key, or null if the key is * not in the map */ public V get(K key); /** * Removes from the key-value pair associated with the specified key * @param key the key * @return the value associated with the key, or null if the key is * not in the map */ public V remove(K key); /** * Returns whether the map contains the key-value pair associated with * the specified key * @param key the key * @return true if the map contains a key-value pair with the specified * key, and false otherwise */ public boolean containsKey(K key); /** * Returns whether the map contains no elements * @return true if the map contains no key-value pairs, and false otherwise */ public boolean isEmpty(); /** * Removes all elements from the map */ public void clear(); /** * Gets the number of key-value pairs in the map * @return the number of key-value pairs in the map */ public int size(); /** * Gets a set of all keys in the map * @return */ public Set keySet(); /** * Gets a set of all values in the map * @return */ public Collection values(); }
Tester
public class Tester { public static void main(String[] args) { ArrayListMap alm = new ArrayListMap(); System.out.println(alm.put("Cindy", 1)); System.out.println(alm.put("Nina", 2)); System.out.println(alm.put("Morgan", 3)); System.out.println(alm.put("Michael", 4)); System.out.println(alm.size()); System.out.println(alm.containsKey("Morgan")); System.out.println(alm.containsKey("Jack")); System.out.println(alm.get("Michael")); System.out.println(alm.values()); System.out.println(alm.keySet()); System.out.println(alm.put("Michael", 6)); System.out.println(alm.get("Michael")); System.out.println(alm.remove("Michael")); System.out.println(alm.remove("Morgan")); System.out.println(alm.remove("Nina")); System.out.println(alm.remove("Cindy")); System.out.println(alm.size()); } }
Related Book For
Understanding Business Ethics
ISBN: 9781506303239
3rd Edition
Authors: Peter A. Stanwick, Sarah D. Stanwick
Posted Date: