



|
|
Byron's CSC212 Web Site
|
Class Notes
Wednesday December 6 , 2000
|
|
|
Word Dictionary Review
Class Notes --
Wednesday December 6 , 2000
CSC212 - December 6, 2000
======================================
Lecture Topic: WORD DICTIONARY PROGRAM
Static Method - Library Class
Instance Method - Application
double d = area(s,c);
(static) private double area(Square s, Circle c)
Represent("c10",p,10)
static private void represent(String c,point p, int n)
Instance Method
if statements are "operators"
returns a boolean
if (mempberp(ls, sounds)
private boolean memberp(String x, String[] sounds)
______________
Filter Routine:
public Word select (String[], sounds) // sounds=int
{
// Filter
Dictionary d = filter (sounds);
return d.select();
}
private Dictionary filter(String[] sounds)
{
Dictionary result = new Dictionary("temp");
for (int i = 0; i< nrElements; i++)
{
// String[] syllables = words[i] syllables();
// String ls = syllables(syllables.length-1);
if (memberp(ls,sounds))
{
result.add(words[i];
}
}
// "Dictionary"
return result;
}
______________
Note:
Write 2nd filter program
<Dictionary>.select(<int>) -> <Word>
by analogy with this one.
For second sort see comments in program above.
3rd select - should be written by using the two
filter programs in sequence.
public Word select(String[] sounds, int ns)
// Create a dictionary of only those words ending in
// the right sounds.
Dictionary ds = filter (sounds);
Dictionary dns = ds.filter(ns);
return dns.select();
// Condition of the "if" statement
public void sort()
{
// if <condition><statement-block>
// Word.less(words[sx], words[px])
for ( int px = 0 ; px < nrElements; px++)
{
for ( int sx = px+1; sx < nrElements; sx++)
if Word.less(words[sx], words[px])
{
Word temp = Words[sx];
Words [sx] = words [px];
Words [px] = temp;
}
}
}
Back to Exam:
Superficial Signatures
double width = <Square>.area;
// Don't replace methods
=========================================================
123456789112345678921234567893123456789412345678951234567
|
|
|