



|
|
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
- new Word () - > < Word >
Create a word by reading information from the standard input stream
- < Word > .length () - > < int >
Return the length of the word
- < Word > .nrSyllables () - > < int >
Return the number of syllables in the word
- < Word > .display ()
Displays the ``properties'' of the Word.
Example:
W- > word- > ``Monday''
Syllables- > ``Mon'' | ``day''
w.display ()
Word: Monday
Syllables: mon day
- < Word > .print ()
Prints the word
- Word.equals (< Word >, < Word >) - > boolean
- Word.less (< Word >, < Word >) - > boolean
Returns true if the 1 st parm is less than the second parm; false if not
- Word.greater (< Word >, < Word >) - > boolean
|
Specification of the Dictionary class
- new Dictionary () - > Dictionary
Create the empty dictionary of words.
- < Dictionary > .add (< Word >)
Add a < Word > to the dictionary.
- < 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''); }
- < Dictionary > .display ();
- < Dictionary > .size (); - > < int >
Number of words in dictionary
- < Dictionary > .search (< Word >) - > < boolean >
- < Dictionary > .search (< String >) - > < Word >
Return the word corresponding to the string or null if not in dicitonary
- < Dictionary > .sort ()
Order the words alphabetically
- < Word > .word () - > < String >
- < 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.
|
|