Byron's CSC212 Web Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
Byron's CSC212 Web Site  
 
 
 
Class Notes

Wednesday November 29 , 2000
 
Word Dictionary Random Generator  

 
  Class Notes  -- Wednesday November 29 , 2000

   
   CSC212 - November 29, 2000
   ==========================
  
   Lecture Topic: DICTIONARY CLASS
  
    A Dictionary
       __________________________
      | tree     | (tree)        |
      | monkey   | (mon   key)   |
      | bear     | (bear)        |
      | prepare  | (pre   pare)  |
      |__________|_______________|
  
  
    d.select ()             // would select any one of the
                            // words at random.
    
    d.select (n)            // would select words with
                            // n syllables.
  
    d.select ("tree","key") // would return a random word
                            // ending in one of these
                            // strings (syllables).
  
    d.select (1,"tree","key")// would return a random word
                             // of one syllable ending in
                             // either "tree" or "key".
  
   On Generating random numbers:
  
     In the    "blue.math.*"
     package is a class called "RandomGenerator" which
     can be used to generate random numbers.
  
    Specifications
  
     new RandomNumber() -> <RandomGenerator>
  
    <RandomGenerator>.uniform(<int>,<int>) -> <int>
  
      This method generates a random integer between the
      first <int> and the second <int> inclusive.
  
    Ex: 
  
      RandomGenerator rg = new RandomGenerator()
      
      for (int x=1; x< 10; x++)
    {
      int rn = rg.uniform(0,100);
      IO.println(rn)
    }
  
   Practice: Implement <Dictionary>.select() -> <Word>
  
     in the Dictionary Class
  
     Instance Variables
  
       private String name;
       private Word[] words;
       private int nrElements;
  
   Select Routine
  
      public Word select()
    {
      RandonGenerator rg = new RandomGenerator();
      int rn = rg.uniform(0,nrElements-1);
      return words[rn];
    }
  
   Second Part of Program 5 Assignment:
  
      Part 2 of Final Programming Challenge
  
    1. Create several (like 3,4, or 5) small dictionaries
       each containing a "part of speach".
       (Article, noun, verb, adjective)
  
       Do this by creating a data file for each dictionary.
  
       And then "Reading" the Dictionary using the
       appropriate functionality.
       (Look at the  begining of lab)
  
       Write a number of methods, each of which will
       generate a "fixed" sort of phrase - at random.
  
       It will be "fixed" in that each time you call it, it
       will generate a similar sentence in terms of parts
       of speach, rythm, & rhyme.
  
    Ex:  SimplePhraseOfType1()
  
         // Might print a sentence consisting of -
  
            Article     The
            Noun        Cat
            Verb        ate
            Article     the
            Adjective   fat
            Noun        mouse
  
       with particular "rythm & rhyme"
  
    2. Suppose: Article, noun, verb, adjective
                are Dictionarys
                (static global Dictionary variables)
  
      static private void simplePhraseOfType1()
     {
    // Article Dictionary
       Word article1 = article.select();
       Word noun1    = noun.select(2);
       Word verb     = verb.select();
       Word article2 = article.select();
       Word adjective= adjective.select();
       Word noun2    = noun.select(2);
    // Write PrintSentence
       printSentence (article1,noun1,verb,article2, +
           adjective,noun2);
     }
     
   3. Use the few methods in some interesting ways.
  
  
   ========================================================
   12345678911234567892123456789312345678941234567895123456