16.3 |
Modify the program in Fig. 16.17 so that the card-dealing method deals a five-card poker hand. Then write the following additional methods:
- Determine if the hand contains a pair.
- Determine if the hand contains two pairs.
- Determine if the hand contains three of a kind (e.g., three jacks).
- Determine if the hand contains four of a kind (e.g., four aces).
- Determine if the hand contains a flush (i.e., all five cards of the same suit).
- Determine if the hand contains a straight (i.e., five cards of consecutive face values).
- Determine if the hand contains a full house (i.e., two cards of one face value and three cards of another face value).
|
16.5 |
Write an application that uses random-number generation to create sentences. Use four arrays of strings, called article, noun, verb and preposition. Create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article, noun. As each word is picked, concatenate it to the previous words in the sentence. The words should be separated by spaces. When the sentence is output, it should start with a capital letter and end with a period. The program should generate 10 sentences and output them to a text area.
The arrays should be filled as follows: The article array should contain the articles "the", "a", "one", "some" and "any"; the noun array should contain the nouns "boy", "girl", "dog", "town" and "car"; the verb array should contain the past-tense verbs "drove", "jumped", "ran", "walked" and "skipped"; and the preposition array should contain the prepositions "to", "from", "over", "under" and "on".
After the preceding program is written, modify the program to produce a short story consisting of several of these sentences. (How about the possibility of a random term-paper writer!)
|
16.6 |
(Pig Latin) Write an application that encodes English language phrases into pig Latin. Pig Latin is a form of coded language often used for amusement. Many variations exist in the methods used to form pig Latin phrases. For simplicity, use the following algorithm:
To translate each English word into a pig Latin word, place the first letter of the English word at the end of the word and add the letters "ay." Thus, the word "jump" becomes "umpjay," the word "the" becomes "hetay" and the word "computer" becomes "omputercay." Blanks between words remain blanks. Assume the following: The English phrase consists of words separated by blanks, there are no punctuation marks and all words have two or more letters. Enable the user to input a sentence. Use techniques discussed in this chapter to divide the sentence into separate words. Method GetPigLatin should translate a single word into pig Latin. Keep a running display of all the converted sentences in a text area.
|
16.7 |
Write a program that reads a five-letter word from the user and produces all possible three-letter words that can be derived from the letters of the five-letter word. For example, the three-letter words produced from the word "bathe" include the commonly used words "ate," "bat," "bet," "tab," "hat," "the" and "tea."
|