The Last Verse Of A Well-Known Nursery Rhyme Scheme

403 Words1 Page

package unit2randomsentences; /* The last verse of a well-known nursery rhyme: This is the farmer sowing his corn That kept the rooster that crowed in the morn That waked the judge all shaven and shorn That married the man all tattered and torn That kissed the maiden all forlorn That milked the cow with the crumpled horn That tossed the dog That worried the cat That chased the rat That ate the cheese That lay in the house that Jack built. Some rules that capture the syntax of this verse: ::= [ and ] ::= this is [ ] the house that Jack built ::= the [ ] that ::= farmer | rooster | judge | man | maiden | cow | dog | cat | cheese ::= kept …show more content…

All the verses of the rhyme can be generated, plus a lot of sentences that make no sense (but still follow the syntax). Note that an optional item like [ ] has a chance of being used, depending on the value of some randomly generated number. The program generates and outputs one random sentence every three seconds until it is halted (for example, by typing Control-C in the terminal window where it is running). */ public class SimpleRandomSentences { static final String[] nouns = { "farmer", "rooster", "judge", "man", "maiden", "cow", "dog", "cat", "cheese" }; static final String[] verbs = { "kept", "waked", "married", "milked", "tossed", "chased", "lay in" }; static final String[] modifiers = { "that crowed in the morn", "sowing his corn", "all shaven and shorn", "all forlorn", "with the crumpled horn" }; public static void main(String[] args) { while (true) { randomSentence();

More about The Last Verse Of A Well-Known Nursery Rhyme Scheme

Open Document