CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
 
Wait , WAIT !!What's that word ? ( Class Notes ( without definitions ) )

Wednesday December 5 , 2000
 
in an application program,  as opposed to a library class,  everything you write is a static method. 

public Word select (String [] Sounds)
{
    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]);
        }
    }
\ttline }
note
write
< dictionary > .select (< int >) -- > < word > By analogy with this one!
The third 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'' sound
    Dictionary ds = filter (sounds);
    Dictionary dns = ds.filter (ns);
    return dns.select ();
 

public void sort ()
{
    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;
            }
        }
    }
}