using System; namespace PS3_Q2 { // // Problem Set 3, Question 2 // Written by Paul Hudak // October 4, 2006 // class Class1 { // // The Crazy Paragraph Program. // Generates a paragraph of 3 to 6 random sentences. // [STAThread] static void Main(string[] args) { // generate one random number generator for entire program Random r = new Random(); // generate random paragraphs until user types something other than "yes" string response; do { CrazyParagraph(r); Console.Write("\nWould you like another paragraph? "); response = Console.ReadLine(); } while (response == "yes"); Console.WriteLine(); } public static void CrazyParagraph(Random r) { Console.WriteLine(); // determine number of sentences int num = r.Next(4) + 3; // generate "num" random sentences while (num>0) { // choose sentence form randomly switch (r.Next(3)) { case 0: Sentence1(r); break; case 1: Sentence2(r); break; case 2: Sentence3(r); break; } num = num-1; } // done Console.WriteLine("\n"); } public static void Sentence1(Random r) { Console.Write("The {0} {1} {2}. ", Adjective(r), Noun(r), Verb(r)); } public static void Sentence2(Random r) { Console.Write("When the {0} {1} saw what was happening, she {2}. ", Adjective(r), Noun(r), Verb(r)); } public static void Sentence3(Random r) { Console.Write("She {0} violently, and then whacked the {1} {2}. ", Verb(r), Adjective(r), Noun(r)); } public static string Verb(Random r) { switch (r.Next(3)) { case 0: return "ran"; case 1: return "hopped"; case 2: return "walked"; default: return "oops"; } } public static string Noun(Random r) { switch (r.Next(3)) { case 0: return "ball"; case 1: return "student"; case 2: return "professor"; default: return "oops"; } } public static string Adjective(Random r) { switch (r.Next(3)) { case 0: return "red"; case 1: return "silly"; case 2: return "sad"; default: return "oops"; } } } }