Byron's CSC212 Web Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
Byron's CSC212 Web Site  
 
 
 
Class Notes

Monday November 13 , 2000
 
Word Dictionary Class Specifications  

 
  Class Notes  -- Monday November 13 , 2000

   
   CSC212 - November 13, 2000
   ======================================
  
   Lecture Topic: SPECIFICATION OF THE WORD CLASS
  
   1) new Word() -> <Word>
  
       Create a word by reading information from the 
       standard input stream.
  
   2) <Word>.length() -> <int>
  
       Return the length of the word.
  
   3) <Word>.nrSyllables() -> <int>
    
       Return the nr of syllables in the word.
  
   4) <Word>.display()
  
       Display the "properties" of the word.
                 _________________
      Ex:  w -> | word ->         |
                |   _________     |
                |  | monday  |    |
                |  |_________|    |
                |                 |
                | syllablles ->   |
                |   ___________   |
                |  | mon | day |  |
                |  |_____|_____|  |
                |_________________|
  
      w.display()    word:      Monday
                     syllables: Mon day
  
   5) <Word>.print()
      
       print the word
  
       w.print -> Monday
  
   6)  Comparrisons:      Static methods
                      vs. Instance methods
          
       Word.equals (<Word>,<Word>) -> boolean
  
   7)  Word.less (<Word>,<Word>) -> boolean
  
       Returns True if the first word is less than the 
       second, False if not. 
  
   8)  Word.greater (<word>,<Word>) -> <boolean>
  
  
   Specification of the Dictionary Class
  
   1)  new Dictionary() -> <Dictionary>  // Constructor
  
       Create an Empty Dictionary of Words.
  
   2) <Dictionary>.add (<Word>)
  
       Add the Word to the Dictionary.
  
   3) <Dictionary>.add (<String>);
  
       Interpret the String as the name of a Data File.
  
       At the begining of the file is a number indicating
       how many words are represented in the file.
  
       This number of "words" will then be read, created,
       and added to the dictionary.
  
    Ex: To create a dictionary by reading three data files.
  
        Dictionary lexicon = new Dictionary();
  
        lexicon.add ("nouns.text");
        lexicon.add ("verb.text");
        lexicon.add (adjectives.text");
  
   4) <Dictionary>.display()
  
   5) <Dictionary>.size() -> <int>
  
   6) <Dictionary>.search (<Word>) -> <boolean>
  
   7) <Dictionary>.sort()
  
       Order the word corresponding to the String or null
       if no such word string exists.
  
   8) <Dictionary>.sort()
  
       Order the words alphabetically.
  
   Implementing:
  
    Word.equals (<Word>),<Word>) -> <boolean>
  
    // static  = not an instance, but the whole class
    // boolean = what is returned
    // equals  = the method name
  
       static public boolean equals (Word w1, word w2)
     {
  
       String w1Word = W1.word();
       String w2Word = w2.word();
       boolean result = w1Word.equals (w2Word);
       return result
     }
              ________________
             |       _______  |
         w1  | word | "cat" | |
             |      |_______| |
             |       _______  |
             | Syll |  cat  | |
             |      |_______| |
             |________________|
  
  
  
    More Word Specification -  "References"
  
    a) <Word>.word() -> <String>
  
    b) <Word>.syllables() -> <String[]>
  
    Implementation
  
      public String word()
    {
      return word;       // an Instance Variable
    }
    
      public String[] syllables()
    {
      return syllables;  // an Instance Variable
  
  
   Establishing - Library Class
     
      Technical - 
      Terminal Objects of implemanting the Word and
      Dictionary classes.
  
      "You"
        L---> Public-html
                   L------> cs1
                             |
          ___________________|______
         |      |        |          |
        site   labs   programs   classes
                       |         |     |
                      word     blue  white 
                       |       |  |      |
             WordTestApp.java IO shapes Words
                   |                    |  \
     import white.words.*;              |   \  
                                        |    \ 
                           Dictionary.java  Word.java
  
  
   =========================================================
   123456789112345678921234567893123456789412345678951234567