Icetigris 0 Newbie Poster

This compiles, runs fine, and generally works, except for one thing. The contains() method doesn't work properly. For some reason table.contains(key) isn't returning the right value, which is thereby messing up the insert() method.

public class HashtableDictionary implements StringDictionaryAlgorithm
{
    static final boolean debug = false;
    Hashtable table = new Hashtable(); 
    int value = 0;
/*
.
.
.
*/

    public boolean contains(java.lang.String key)
    {
        boolean isItThere = true;
        isItThere = table.containsKey(key);
        return isItThere;
    }

 /*
.
.
.
*/

    public boolean insert(java.lang.String key)
    {
        boolean didItAdd = true;
        boolean duplicate = true;

        duplicate = table.contains(key);

      if(duplicate == true)
      {
          didItAdd = false;
      }
      else if(duplicate == false)
      {
        Object whut = new Object();
        whut = table.put(key, value);
        whut = table.get(key);
        value++;
        if(whut == null)
        {
          didItAdd = false;
        }
      }
        return didItAdd;
    }

  public static void main(String[] args)
  {
    System.out.println("Here's what you want to use as keys in the hashtable: ");

    for (int i=0; i<args.length; i++)
    {
        System.out.print(args[i] + " ");
    }
    System.out.print("\n");

    HashtableDictionary dictionary = new HashtableDictionary();
    boolean added = true;
    boolean contains = false;
   
    for (int i=0; i<args.length; i++)               //ADD THINGS TO LIST
    {
      added = dictionary.insert(args[i]);

      if(added == false)
      {
        System.out.println("something didn't add right: " + args[i]);
      }
    }

    System.out.println("Your table:");
    System.out.println(dictionary.table.toString());

    String whatToFind = "dongs";

    contains = dictionary.contains(whatToFind);
      
    if(contains == false)
    {
      System.out.println("string isn't in the list: " + whatToFind);
    }
    else if(contains == true)
    {
      System.out.println("string is in the list: " + whatToFind);
    }

 
  }

}

Any ideas? Thanks

EDIT:
DISREGARD THAT;
I just realised I should have used containsKey() not contains().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.