Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

save file to disk java

public class Test {

   static final String[] conjunction = { "and", "or", "but", "because"};

   static final String[] proper_noun = { "Fred", "Jane", "Richard Nixon","Miss America"};

   static final String[] common_noun = { "man", "woman", "fish", "elephant", "unicorn"};                                  

   static final String[] determiner = { "a", "the", "every", "some"};

   static final String[] adjective = { "big", "tiny", "pretty", "bald"};

   static final String[] intransitive_verb = { "runs", "jumps", "talks", "sleeps"};

   static final String[] transitive_verb = { "loves", "hates", "sees", "knows", "looks for", "finds"};

  

  public static void main(String[] args) {

      while (true) {

         randomSentence();

      System.out.println(".
");

         try {

             Thread.sleep(3000);

         }

         catch (InterruptedException e) {

         }

      }

   }

   static void randomSentence() {

      randomNounPhrase();

              randomVerbPhrase();

      if (Math.random() > 0.75) {

              System.out.print(" " + randomItem(conjunction));

              randomSentence();

      }

   }

   static void randomNounPhrase() {

          if (Math.random() > 0.75)

             System.out.print(" " + randomItem(proper_noun));

          else

          {

             System.out.print(" " + randomItem(determiner));

             if (Math.random() > 0.5)

         System.out.print(" " + randomItem(adjective)+".");

                System.out.print(" " + randomItem(common_noun));

                 if (Math.random() > 0.5){

                      System.out.print(" who" );

                      randomVerbPhrase();

                 }

          }

     }

      static void randomVerbPhrase() {

          if (Math.random() > 0.75)

             System.out.print(" " + randomItem(intransitive_verb));

                else if (Math.random() > 0.50) {

                        System.out.print(" " + randomItem(transitive_verb));

                        randomNounPhrase();

                }

                else if (Math.random() > 0.25)

                    System.out.print(" is " + randomItem(adjective));

                else {

                    System.out.print(" believes that");

                    randomNounPhrase();

                    randomVerbPhrase();

                }

       }

   static String randomItem(String[] listOfStrings){

       return listOfStrings[(int)(Math.random()*listOfStrings.length)];

   }

}
Comment

PREVIOUS NEXT
Code Example
Java :: combobox index out of bound javafx 
Java :: what does system.out.println(y + " ") result 
Java :: Java How to use NavigableMap? 
Java :: Java try...finally block 
Java :: java truncate bigdecimal 
Java :: java can an object be used as a key 
Java :: madhava kripa 
Java :: reading 2d array in java 
Java :: md5 java ee 
Java :: print 1 to 10 using for loop in java 
Java :: convert kotlin code to java online 
Java :: rotate vector 3d java 
Java :: convert kotlin code to java 
Java :: search in row and column sorted matrix leetcode 
Java :: how to pass parameters to xsl file 
Java :: trier un tableau de string java 
Java :: Java create an object of the non-static class Reptile 
Java :: jframe centerlaized 
Java :: sum of number from list 
Java :: string equlity 
Java :: find if element is powers of 2 
Java :: code to close dialog containg layout 
Java :: ternario java 
Java :: Java Enable assertion in package names 
Java :: java program on stack for beginners 
Java :: leak canary 
Java :: has 8 digit in number 
Java :: jdbc outside of ide 
Java :: run app by package android 
Java :: java tcp readline not working 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =