Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions