// save this file as Optimist.java package picnic; class Optimist { public static void main (String [ ] args) { double x; // declares x to be an allowable name for a decimal int noun_choice, verb_choice, adj_choice; // declares these as names for integers // next we declare and initialise three arrays of words String [] noun = {"ribbon", "cuckoo", "nest", "sky", "sea"}; String [] verb = {"flew", "floated", "soared", "dived"}; String [] adj = {"blue", "high", "bald", "rotund", "moribund", "tiny", "extinct"}; String e = "\n"; // a new line character String space = " "; for (int i=1; i<=20; i++){ // a for loop to create 20 random "words" x = 100 * Math.random(); // a random no between 0 and 100 to which array of words to use next // now we pick integers to help pick a word randomly from the chosen array of words noun_choice = (int) (noun.length * Math.random()); // a random no between 0 and 5 (excl 5) verb_choice = david(verb); // a random no between 0 and 4 (excl 4) using the delegated method below adj_choice = david(adj); // a random no between 0 and 7 (excl 7), also using david if (x < 10) System.out.print(noun[noun_choice] + space); else if (x < 30) System.out.print(verb[verb_choice] + space); else if (x < 60) System.out.print(adj[adj_choice] + space); else System.out.print(e); // new line //i++; } // end while loop } // end main method public static int david (String [] some_array) { // input is some array of Strings, output is an integer int temp = (int) (some_array.length * Math.random()); // a random integer location within the array return temp; } // end david method } // end Optimist