



|
|
CS1 Course Site
|
Class Notes
Monday November 13 , 2000
|
|
Specifications of the Word class
(1) new Word () -- < Word >
Create a word by reading information
from the standard input stream.
|
(2) < Word > .length () -- < int >
Returns the length of the word.
|
(3) < Word > .nrSyllables () -- < int >
Returns the # of syllables in the word.
|
(4) < Word > .display ()
Displays the ``properties'' of the word.
|
(5) < Word > .print ()
Prints the word.
|
(6) Word.equals (< Word >, < Word >) -- < boolean >
|
(7) Word.less (< Word >, < Word >) -- < boolean >
Returns true if the first word is less
than the second and false if not.
|
(8) Word.greater (< Word >, < Word >) -- < boolean >
|
Specifications of the Dictionary class
(1) new Dictionary () -- < Dictionary >
Create the 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 beginning 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.
Example
To create a dictionary by reading three
data files....
Dictionary lexicon = new Dictionary ();
lexicon.add (``nouns.text'');
lexicon.add (``verbs.text'');
lexicon.add (``adjectives.text'');
|
(4) < Dictionary > .display ()
|
(5) < Dictionary > .size () -- < int >
|
(6) < Dictionary > .seach (< Word >) -- < boolean >
|
(7) < Dictionary > .search (< String >) -- < Word >
Return the word corresponding to the string,
or null if no such word exists.
|
(8) < Dictionary > .sort ()
Order the words alphabetically.
|
Implementing...
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;
}
|
More word specification:
(9) < Word > .word () -- < String >
|
(10) < Word > .syllables () -- < String [] >
|
9 and 10 are referencers.
Implementation...
public String word ()
{
return word;
}
|
word is an instance variable.
public String [] syllables ()
{
return syllables;
}
|
syllables is an instance variable.
|
|