P Dunn's Super CS1 Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
P Dunn's Super CS1 Site  
 
 
 
Class Notes

Monday November 13 , 2000
 
Synopsis
Today's class we discussed and specified the Word and Dictionary classes that we will be writing.
  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 number of syllables in the word
  4. < Word > .display ()
    Displays the ``properties'' of the Word.
    Example:
    W- > word- > ``Monday''
    Syllables- > ``Mon'' | ``day''
    w.display ()
    Word:   Monday
    Syllables:   mon day
  5. < Word > .print ()
    Prints the word
  6. Word.equals (< Word >,  < Word >) - > boolean
  7. Word.less (< Word >,  < Word >) - > boolean
    Returns true if the 1 st parm is less than the second parm;  false if not
  8. Word.greater (< Word >,  < Word >) - > boolean
 

Specification of the Dictionary class  

  1. new Dictionary () - > Dictionary
    Create the empty dictionary of words.
  2. < Dictionary > .add (< Word >)
    Add a < Word > to the dictionary.
  3. < Dictionary > .add {< String >

    Interpret the string ad the name of a datafile at the beginning of the file is a number indicating how many word 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 there data files
    Dictionary.lexicon = new Dictionary ();
    lexicon.add ( ``nouns.txt'');
    lexicon.add ( ``verbs.txt'');
    lexicon.add ( ``adjective.txt'');  }
  4. < Dictionary > .display ();
  5. < Dictionary > .size ();  - > < int >
    Number of words in dictionary
  6. < Dictionary > .search (< Word >) - > < boolean >
  7. < Dictionary > .search (< String >) - > < Word >
    Return the word corresponding to the string or null if not in dicitonary
  8. < Dictionary > .sort ()
    Order the words alphabetically
  9. < Word > .word () - > < String >
  10. < Word > .syllables () - > < String [] >
 

Implementation
  Word.equals (< Word >,  < Word >) - > < boolean >
 
  static public boolean equals (Word w1,  Word w2)
  {
  String w1Word = w1.Word ();
  String w2Word = w2.Word ();
  boolean result = w1Word.equals (w2Word);
  return result;
 
}  
  public String Word ()
  {
  return Word;  / /instance variable
 
}  
  public String [] syllables ()
  {
  return syllables;
 
}
 

Lab discussion ensued about the aspects of librarying a class in Java.   The concept of packages.   Really cool stuff.