// HW08_2d.java // Tim Hilby // Created on April 12, 2006 import java.util.Random; import java.util.Scanner; public class HW08_2d { // random number generator used by all functions public static Random r = new Random(); // This program simply follows the description: // In the language of an alien race, // all words take the form of Blurbs. public static String Blurb() { // A Blurb is a Whoozit ... String result = Whoozit(); // ...followed by one or more Whatzits. int num = r.nextInt(9) + 1; for (int i = 0; i < num; i++) { result += Whatzit(); } return result; } public static String Whoozit() { // A Whoozit is the character 'x' ... String result = "x"; // ...followed by zero or more 'y's. int num = r.nextInt(9); for (int i = 0; i < num; i++) { result += "y"; } return result; } public static String Whatzit() { // A Whatzit is a 'q' ... String result = "q"; // ...followed by either a 'z' or a 'd', ... int num = r.nextInt(2); if (num == 0) { result += "z"; } else // (num == 1) { result += "d"; } // ...followed by a Whoozit. result += Whoozit(); return result; } public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("This program makes Blurbs."); System.out.println("How many blurbs do you want?"); int n = scan.nextInt(); while (n > 0) { System.out.println(Blurb()); n--; } } }