CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

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

Wednesday November 15 , 2000
 
\beginolrn
  • In the lab for this week you ``implement'' some of the word class...
    • new Word () -- > < word >
    • new Word (< String >,  < string [] >) -- > < word >
    • < word > .word () -- > < string >
    • < word > .syllables () -- > < string [] >
    • < word > .length () -- > < int >
    • < word > .nrSyllables () -- > < int >
    • < word > .describe ()
    • < word > .print ()
    • < word > .length (< word >,  < word >) -- > < boolean >
    • < word > .lastSyllable () -- > < string >
  • By analogy with the lab,  start implimenting the dictionary class.
    • new Dictionary (< string >) -- > < dictionary >
    • < dictionary > .add (< word >)
    • < dictionary > .add (< string >) (filename)
    • < dictionary > .display ()
  • Add and test one element of functionality of the word class at a time untill it is complete
    • implement and test
  • One at a time implement and test the items of functionality of the dictionary class.
    A dictionary...   d
    name -- > ``Animals''
    words -- > An array of the words,  with thier syllables
    ``cat'' | ``cat''
    ``tiger'' | ``ti'' | ``ger''
    ``elephant'' | ``el'' | ``e'' | ``phant''
    ``zebra'' | ``ze'' | ``bra''
    d.name () =  ``Animals''
    d.words () = returns the array above
    d.size () = 9
    d.element (2) =  ``elephant'' | ``el'' | ``e'' | ``phant''
    d.display () = Animal cat (cat) tiger (ti | ger) elephant (el | e | phant) zebra (ze | bra)
    note this is easy...   use...
    • a for statement
    • print method for word objects.
    Write a method to search an array of integers for a given integer.   Unlike the search method of your Dictionary class,  this will be a static method.
    static private boolean search (int x,  int a [])
    {
        for (int i = 0;  i < a.length;  i + +)
        {
            if (a [i] == x)
            {
                return true;
            }
        }
        return false;
    }
    Sorting
    The code...
    for (int p = 0;  p < a.length;  p + +)
    {
        for (int s = p + 1;  s < a.length;  s + +)
        {
            if (a [p] > a [s])
            {
                int temp = a [p];
                a [p] = a [s];
                a [s] = temp;
            }
        }
    }