/** Let's try to make a couplet based on the Lobster Quadrille. * S --> "Here are some couplets..." A * A --> e | CA (C stands for couplet) * C --> "Will you walk a little faster said a whiting to a " T * T --> "snail" M "tail" | "baboon" M "spoon" | "gnu" M "shoe" | * "chimpanzee" M "knee" | "cat" M "hat" | "dog" M "log" | * "fox" M "box" | "fish" M "dish" | "sable" M "table" * M --> "There's a porpoise close behind me and he's treading on my " * * We could make the middle part (M) more interesting by adding different * followers and verbs besides porpoise and treading. */ public class Lobster { public static void main(String [] args) { String S = "Here are some couplets.\n" + A(); System.out.println(S); } // Let's have a 80% chance of continuing the story! public static String A() { if (Math.random() < .2) return ""; else return C() + A(); } public static String C() { return "\nWill you walk a little faster said a whiting to a " + T() + "\n"; } public static String T() { int i = (int) (9.0 * Math.random()); switch(i) { case 0: return "snail" + M() + "tail"; case 1: return "baboon" + M() + "spoon"; case 2: return "gnu" + M() + "shoe"; case 3: return "chimpanzee" + M() + "knee"; case 4: return "cat" + M() + "hat"; case 5: return "dog" + M() + "log"; case 6: return "fox" + M() + "box"; case 7: return "fish" + M() + "dish"; default: return "sable" + M() + "table"; } } public static String M() { return "\nThere's a porpoise close behind me and he's treading on my "; } }