CS 102 (Spring 2003)
Quiz 1: Packages and Protection

Quiz Posted Given in class
28 Jan 30 Jan


Lab Section:

  1. We cleaned up words and phrases by deleting punctuation from Strings. Suppose we want to add a method to KWIC:
      public boolean isPunctuation(char ch)
    which indicates whether the supplied character is a puncutation symbol. and the constructor for KWIC now also takes a String:
      public KWIC(String punctuationChars)
    so that if I do
      KWIC kwic = new KWIC(".,!?");
    then every character in the supplied string should be treated as punctuation.

    Why can or cannot the isPuncutation method be a static method for KWIC?

  2. What objects have access to a method that is declared protected?
  3. What objects have access to a method that is declared with "default" protection (no modifier specified)?
  4. When getPhrases(Word w) does not find w in the Hash Map, it returns an iterator of an empty set, perhaps by doing:
      return (new HashSet()).iterator();
    How can the Singleton pattern be applied here to save on instances of HashSets?

Last modified 19:11:21 CST 29 January 2003 by Ron K. Cytron