Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

string1 attempt

By: ace on Jun 9th, 2010  |  syntax: None  |  size: 4.04 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Iterator;
  4. import java.util.Random;
  5. import java.util.StringTokenizer;
  6. /**
  7.  * Write a description of class AlanisMorissetteLyrics here.
  8.  *
  9.  * @author (your name)
  10.  * @version (a version number or a date)
  11.  */
  12. public class AlanisMorissetteLyrics
  13. {
  14.    
  15.  
  16.     /**
  17.      * Constructor for objects of class AlanisMorissetteLyrics
  18.      */
  19.     public AlanisMorissetteLyrics()
  20.     {
  21.  
  22.     }
  23.  
  24.     /**
  25.      * An example of a method - replace this comment with your own
  26.      *
  27.      * @param  y   a sample parameter for a method
  28.      * @return     the sum of x and y
  29.      */
  30.    /* public String subWords(List <String>)
  31.     {
  32.        
  33.        
  34.     }*/
  35.    
  36.    
  37.     public String subNoun(String string, ArrayList<String> nouns)
  38.     {
  39.         String s = string;
  40.         int index = 0;
  41.         while (index <= nouns.size() -1)
  42.             {
  43.                
  44.                return nouns.get(0);
  45.             }
  46.            
  47.            
  48.             return nouns.get(0);
  49. }
  50.    
  51. public String subVerb(String string, ArrayList<String> verbs)
  52.     {
  53.         String s = string;
  54.         int index = 0;
  55.         while (index <= verbs.size() -1)
  56.             {
  57.                
  58.                return verbs.get(0);
  59.             }
  60.            
  61.            
  62.             return verbs.get(0);
  63. }
  64.  
  65. public String subAdj (String string, ArrayList<String> adjs)
  66.     {
  67.         String s = string;
  68.         int index = 0;
  69.         while (index <= adjs.size() -1)
  70.             {
  71.                
  72.                return adjs.get(0);
  73.             }
  74.            
  75.            
  76.             return adjs.get(0);
  77. }
  78.  
  79. public String subWords(String string, ArrayList<String> nouns, ArrayList<String> verbs,
  80. ArrayList <String> adjs)
  81. {
  82. String stringOne = "";
  83. String[] result = string.split("\\s");
  84. for (String word : result)
  85.  
  86.    {
  87.  
  88.        if (word.equals("noun"))
  89.                 {
  90.                     //System.out.println("" + subNoun(word, nouns));
  91.                    // return subNoun (word, nouns);  
  92.                    //string.replace("noun", subNoun(word, nouns));
  93.                    String stringOne = string.replace("noun", subNoun(word, nouns));
  94.                 }
  95.                
  96.         if (word.equals("verb"))
  97.                 {
  98.                     System.out.println("" + subVerb(word, verbs));
  99.                     //string.replace("verb",  subVerb(word, verbs));
  100.                     //System.out.println(string);
  101.                     String string1 = string.replace("verb", subVerb(word, verbs));
  102.                  
  103.                 }
  104.                
  105.               if (word.equals("adjective"))
  106.                 {
  107.                   //System.out.println("" + subAdj(word, adjs));
  108.                   //return subAdj (word, adjs);
  109.                   String string1 = string.replace("adjective", subAdj(word, adjs));
  110.                 }
  111.                
  112.                
  113.                
  114.     }
  115.     return string;
  116.    
  117. }
  118.  
  119. //string.replace ("noun", nouns.get(0));
  120. //string.replace ("verb", verbs.get(0));
  121. //string.replace ("adjective", adjs.get(0));
  122. /*int resultIndex = 0;
  123.  
  124. while (resultIndex <= result.size())
  125.     {
  126.         if (string.equals ("noun"))
  127.             {
  128.                 string.replace("noun", nouns.getIndex(resultIndex));
  129.             }  
  130.             resultIndex++;
  131.            
  132.         }
  133.  
  134.     if (string.equals("noun"))
  135.     {
  136.            System.out.println("string" + subNoun(string, nouns));
  137.             return subNoun(string, nouns);
  138.         }  
  139.  
  140.     if (string.equals("verb"))
  141.     {
  142.         return subVerb(string, verbs);
  143.     }
  144.    
  145.           if(string.equals("adjective"))
  146.           {
  147.                         return subAdj(string, adjs);
  148.                     }
  149.                
  150.                     return string;
  151.                 }*/
  152.                
  153.  /*public String generate(randomNouns, randomVerbs, randomAdjectives)
  154.     {
  155.         randomNouns = new Random();
  156.         randomVerbs = new Random();
  157.         randomAdjectives = new Random();
  158.     }*/
  159.    
  160.    
  161. }