Map Problems


  1. Create a class that uses a TreeMap to hold names mapped to phones numbers.
    • public void add(String n,String p)
    • public void print() // use iterator
    • public void print2() // use for-each loop
    • public void printNamesInReverseOrder() // you can use a local stack
    • public void printNamesAndPhone()
    • public void printOnlyPhone()
    • Public void printName(String phone) // print the name given the phone #
  2. Create a class that uses a TreeMap to hold names mapped to an int array of grades.
    • public void add(String na, int[] ar)
    • public void printAvg(String na)
    • public void printAll(); // print all names and averages
    • public String valedictorian() // returns student with highest average
    • public removeFailures() // remove students from tree whose avg is under 60
  3. Write a class that will read words from a text file and then counts the occurrences of words in the file. It will then print out the words that are in the file more than 3 times.
  4. Extend the Tree map class (TreeMap2) so that it has a printKeys() method that will print out all the keys.
  5. Add a method printValues() to the TreeMap2 class that will print out all the Values in the TreeMap.
  6. Add a method printAll() to the TreeMap2 class that will print out all the Keys and the Values in the TreeMap.