Make your own free website on Tripod.com

Assignment - Map an occupation to a class that contains a First
name last name and phone number. Use Treemap class.
Extend TreeMap class with

 boolean inThere(Object o)
 and
 printValue(Object o)

 From client you should be able to :

 1. Get phone for worker
 2. Add or replace a worker
 3. Delete a worker
 4. Print occupations on file

**********************************

import java.util.TreeMap;

class TreeMapHelper extends TreeMap
 {
  boolean inThere(Object key)
    {if (get(key)==null)
       return false;
      return true;
    }

  void printValue(Object key)
   {if (containsKey(key))
     {data d = (data)get(key);
      System.out.println(d.getFirst() + " " + d.getLast() + " " + d.getPhone());
     }
   }
}
*********************************
import java.io.*;
import java.util.Set;

public class treemaptester
{static public input in = new input();

	public static void main(String[] args) throws IOException
	{TreeMapHelper t = new TreeMapHelper();
    String s,f,l,te;
    int x = 0;
    while (x != 5)
     {System.out.println("1. Get phone for worker ");
      System.out.println("2. Add or replace a worker ");
      System.out.println("3. Delete a worker ");
      System.out.println("4. Print occupations on file ");
      x = in.getInt();
      if (x ==1)
       {System.out.println("Enter occupation");
        s = in.getString();
        if (t.inThere(s))
         t.printValue(s);
        else
         System.out.println("None of those yet ");
       }
      if (x==2)
       {System.out.println("Enter  occupation ");
       s =in.getString();
        System.out.println("Enter First name ");
        f =in.getString();
        System.out.println("Enter Last name ");
        l =in.getString();
        System.out.println("Enter telephone");
        te=in.getString();
	    data d = new data(f,l,te);
	    t.put(s,d);
	   }
	   if (x==3)
	    {System.out.println("Enter  occupation ");
        s=in.getString();
        t.remove(s);    // although remove not in TreeMap AP subset
	    }
	   if (x==4)
	    {System.out.println(t.keySet());
	     }
     } while (x != 5);
 }
}