Question: I am working with the following code that I want to generate 10 random poems and 2 haikus, however when i run it, it only

I am working with the following code that I want to generate 10 random poems and 2 haikus, however when i run it, it only displays the 10 poems and not the haikus. Can annyone tell me why it is not showing the haikus? Thank you.

Here is the code:

public class Program4 { //function to generate random number between 0 and n-1 public static int rand( int n){ return (int) ( Math.random() * n ); }

public static void printSentence(String sentence) { System.out.println(Character.toUpperCase(sentence.charAt(0)) + sentence.substring(1)); }

public static void main ( String[] args ) { int numberOfPoems = 10; int numberofHaikus = 2; String[] themes = { "Einstein", "Memory", "Limits", "Basketball", "Vacation", "Golf", "Football", "Dogs", "Beach", "Snow", "Cinematography", "Nature"}; String [] THEMATIC_TITLE = { "EINSTEIN", "MY MEMORY", "PUSH YOURSELF", "THE GAME", "TAKING A TRIP", "THE PERFECT HOBBY", "FOOTBALL", "A TRUE FRIEND", "SUNNY DAYS", "WHITEOUT", "CREATING MAGIC", "LOOK AROUND"}; String [] thematic_noun = { "equation", "flashback", "restriction", "rebound", "summer", "swing", "touchdown", "love", "sand", "snow", "film","trees"};

String [] Thematic_ending_phrase = { "A stroke of genius", "Forever remembered", "Off limits", "Slam dunk", "A place in the sun", "Hole in one", "Play the game", "A man's best friend", "Rising tide", "A cold life", "Call to action", "A beautiful view"}; String [] adjectives = { "vivid","silent", "old", "frozen", "brave", "clever", "strong", "big", "calm","creepy", "fresh", "powerful"};

String [] verbs = { "billow in", "jump over", "flutter by", "hover by", "settle into", "evolve into", "run by", "walk into", "smile with", "look at", "push around", "glance across"}; String [] nouns = { "fire", "ice", "time", "man", "world", "work", "hand", "problem", "night", "school", "money", "history"}; String [] prepositions = { "with", "by", "for", "below", "above", "between", "into", "toward", "near", "over", "at", "across"}; String[] haikuWithsyllable = {"Splash", "Strange", "again", "speckled", "southern", "northern", "eastern", "western", "peaceful", "table", "ahead", "swimming", "across", "current"}; String[] haikuWithSingleword = {"with", "by", "for", "below", "above", "between", "into", "toward", "near", "over", "at", "in", "the", "Life", "Fish", "water", "runs"}; //generate 10 poems for(int i=1;i<=numberOfPoems;i++) { int theme = ( int ) ( Math.random ( ) * themes.length ); System.out.println( " A Poem based on the theme: " + themes[ theme ] + " " ); System.out.println( THEMATIC_TITLE[theme] ); //same THEMATIC_TITLE printSentence( adjectives[ rand(adjectives.length) ] + " " + thematic_noun[theme] ); //same thematic_noun //random verbs and nouns and prepositions printSentence( verbs[ rand(verbs.length) ] + " " + nouns[ rand(nouns.length) ] ); printSentence( nouns[ rand(nouns.length) ] + " " + prepositions[ rand(prepositions.length) ] + " " + nouns[ rand(nouns.length) ] + " " + verbs[ rand(verbs.length) ] + " " + nouns[ rand(nouns.length) ] ); printSentence( " " + Thematic_ending_phrase[ theme ] +" "); //same Thematic_ending_phrase } System.out.println("-------------HAIKUS------------------"); for (int i = 1; i <= numberofHaikus; i++) { for (int j = 0; j < 3; j++) { String syllable1 = haikuWithsyllable[(int) (Math.random() * haikuWithsyllable.length)]; String syllable2 = haikuWithsyllable[(int) (Math.random() * haikuWithsyllable.length)]; String singleWord = haikuWithSingleword[(int) (Math.random() * haikuWithsyllable.length)]; if (j == 1) { String syllable3 = haikuWithsyllable[(int) (Math.random() * haikuWithsyllable.length)]; printSentence(syllable1 + " " + syllable2 + " " + singleWord + " " + syllable3); } else { printSentence(syllable1 + " " + singleWord + " " + syllable2); } } System.out.println(); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!