



|
|
CS1 Course Site
|
Wait , WAIT !!What's that word ? ( Class Notes ( without definitions ) )
Wednesday November 29 , 2000
|
|
a dictionary
d
tree | (tree)
monkey | (mon | key)
bear | (bear)
Prepare | (prepare)
d.select () would selevt any one of the words at random.
d.select (2) would select either mon | key or pre | pare.
d.select ( ``ar'' |'' key'') would return a random word ending in these strings (syllables).
d.select (1, [ ``key'' |'' pare'']) would return a random word of one syllable ending in either ``key'' or ``pare''
On generating random numbers
in the blue.math package is a class called randomGenerator which you can use to generate random numbers.
Specifications
new RandomGenerator () -- > < 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);
}
Do this...
Implement
< dictionary > .select () - > < word > in the dictionary class
recall the instance variables.
private String name;
private Word [] words;
private int nrElements;
public Word select ()
{
RandomGenerator rg = new RandomGenerator ();
for (int x = 1; x < = 10; x + +; x + +)
{
int rn = rg.uniform (0, d.length-1);
}
return words [rn];
}
Part 2 of Final Programming Challeng
- Create sever (like 3 or 4 or 5) small Dictionaries, each containing a ``part of speech.'' (Article, noun, verb, adjective. )
Do this by creating a data file for each dictionary and then ``reading'' the dictionary using the appropriate functionality.
- Write a number of methods each of which will generate a ``dixed'' 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 speech, rhythm, and rhyme.
Ex
SimplePhraseOfType1 () might print a sentence consisting of...
- An article. the
- A noun. cat
- A verb. ate
- An article. the
- An adjective. rabid
- a noun. mouse
with particular ``rhythm + rhyme''
Suppose
article, soun, verb, adjective are dictionaries. (static global Dictionary variables)
static private void simplePhraseOfType1 ()
{
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);
printSentence (article1, noun1, verb, article2, adjective, noun2);
}
- Use the few methods in some interesting ways.
|
|