



|
|
CS1 Course Site
|
Wait , WAIT !!What's that word ? ( Class Notes ( without definitions ) )
Monday November 13 , 2000
|
|
Specification of the word class
- new Word () -- > < word >
create a word by reading information from the standard input screen.
- < word > .length () -- > < int >
return the length of the word.
- < word > .display ();
Display the ``properties'' of the word.
Ex
w -- > word -- > ``monday'' syllables -- > ``| mon | day |''
w.display ()
word: monday
syllables: mon | day
- < word > .print ()
print the word
w.print ();
monday
- Word.equals (< word >, < word >) -- > < boolean >
- Word.less (< word >, < word >) -- > < boolean >
returns true if the first word is less than the second one; false if not.
- word.greater (< word >, < word >) -- > < boolean >
Specifications of the Dictionary class
- new Dictionary () -- > < dictionary >
create s an empty dictionary of words.
- < dictionary > .add (< word >)
add the word to the dictionary
- < 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
Ex
To change a dictionary by reading these files...
Dictionary lexicon = new Dictionary ();
lexicon.add ( ``nouns.text'');
lexicon.add ( ``verbs.text'');
lexicon.add ( ``adjectives.text'');
- < dictionary > .display ()
- < dictionary > .size () -- > < int >
- < dictionary > .search (< word >) -- > < boolean >
- < dictionary > .search (< string >) -- > < int >
returns the word corrisponding to the string - or ``null'' if no such word exists.
- < dictionary > .sort ()
Order the words alphabetically, implimenting...
Word.eaquals (< word >, < word >) -- > < boolean >
- < Word > .word () -- > < string >
- < Word > .syllables () -- > < String [] >
static public boolean equals (Word w1, Word w2)
{
w1 -- > word: ---- syllables: ----
w2 -- > word: ----- syllables: -----
String w1Word = w1.word ();
String w2Word = w2.word ();
boolean result = w1Word.equals (w2Word);
return result;
}
Implimentation
public string word ()
{
return word;
}
public String [] syllables ()
{
return syllables;
}
|
|