title: Writing a random sentence generator in Java
body: <p>I am trying to create a program that generates random sentences in English (according to general English syntax rules). </p>
  
  <p>I keep getting a bug with my subroutine <code>randomSentence()</code>. What have I missed? Also any suggestions on how I can simplify everything?</p>
  
  <p>The error I am receiving is:</p>
  
  <pre><code>Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
  The method print(boolean) in the type PrintStream is not applicable for the arguments (void)
  at SentenceGenerator.randomSentence(SentenceGenerator.java:80)
  at SentenceGenerator.main(SentenceGenerator.java:86)
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Random;
  
  public class SentenceGenerator {
  
      private StringData[] stringData;
      // An array containing all of the possible words. This is a nested class.
  
      /**
      * An object of this type holds the word that will be randomly chosen and printed
      */
      public class StringData {
          String[] conjunction = {"and", "or", "but", "because"};
          String[] proper_noun = {"red", "Jane", "Richard Nixon", "Miss America"};
          String[] common_noun = {"man", "woman", "fish", "elephant", "unicorn"};
          String[] determiner = {"a", "the", "every", "some"};
          String[] adjective = {"big", "tiny", "pretty", "bald"};
          String[] intransitive_verb = {"runs", "jumps", "talks", "sleeps"};
          String[] transitive_verb = {"loves", "hates", "sees", "knows", "looks for", "finds"};
  
          //find out how many words there are in each list
          int conjunctionLength = conjunction.length;
          int proper_nounLength = proper_noun.length;
          int common_nounLength = common_noun.length;
          int determinerLength = determiner.length;
          int adjectiveLength = adjective.length;
          int intransitive_verbLength = intransitive_verb.length;
          int transitive_verbLength = transitive_verb.length;
  
          //Generate random numbers
          int rand1 = (int) (Math.random()*conjunctionLength);
          int rand2 = (int) (Math.random()*proper_nounLength);
          int rand3 = (int) (Math.random()*common_nounLength);
          int rand4 = (int) (Math.random()*determinerLength);
          int rand5 = (int) (Math.random()*adjectiveLength);
          int rand6 = (int) (Math.random()*intransitive_verbLength);
          int rand7 = (int) (Math.random()*transitive_verbLength);
  
          String word1 = conjunction[rand1];
          String word2 = proper_noun[rand2];
          String word3 = common_noun[rand3];
          String word4 = determiner[rand4];
          String word5 = adjective[rand5];
          String word6 = intransitive_verb[rand6];
          String word7 = transitive_verb[rand7];
      }
  
  
      static void Sentence() {
          String sentence() = SimpleSentence();
      }
  
      /**
       * subroutine that defines how SimpleSentence is put together, nesting NounPhrase and VerbPhrase subroutines
       */
  
      public static String SimpleSentence() {
          String simple_sentence = NounPhrase() + VerbPhrase();
          return "";
      }
  
      /**
       * subroutine that defines the nested variable NounPhrase
       */
      public static String NounPhrase() {
          String noun_phrase = proper_noun[word2], determiner[word4], common_noun[word3]; 
          return "";
      }
  
      /**
       * subroutine that defines the nested variable VerbPhrase
       */
      static void VerbPhrase() {
          String verb_phrase = intransitive_verb[word6], transitive_verb[word7], NounPhrase();
      }
  
      /**
       * Final subroutine that prints out the random sentence
       */
      public static void randomSentence() {
          System.out.print(randomSentence());
      }
  
      public static void main(String[] args) {
          while (true) {
              randomSentence();
              System.out.println(".\n\n");
              try {
                  Thread.sleep(3000);
              }
              catch (InterruptedException e) {}
          }
      }
  }
  </code></pre>