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

subWords method2

By: ace on Jun 9th, 2010  |  syntax: None  |  size: 3.73 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[] result = string.split("\\s");
  83. for (String word : result)
  84.    {
  85.  
  86.        if (word.equals("noun"))
  87.                 {
  88.                     System.out.println("" + subNoun(word, nouns));
  89.                    // return subNoun (word, nouns);  
  90.                    string.replace("noun", subNoun(word, nouns));
  91.                 }
  92.                
  93.            if (word.equals("verb"))
  94.                 {
  95.                     System.out.println("" + subVerb(word, verbs));
  96.                     string.replace("verb",  subVerb(word, verbs));
  97.                     ;
  98.                 }
  99.                
  100.               if (word.equals("adjective"))
  101.                 {
  102.                   System.out.println("" + subAdj(word, adjs));
  103.                   //return subAdj (word, adjs);
  104.                   string.replace("adjective", subAdj(word, adjs));
  105.                 }
  106.                
  107.     }
  108.     return string;
  109.    
  110. }
  111.  
  112. //string.replace ("noun", nouns.get(0));
  113. //string.replace ("verb", verbs.get(0));
  114. //string.replace ("adjective", adjs.get(0));
  115. /*int resultIndex = 0;
  116.  
  117. while (resultIndex <= result.size())
  118.     {
  119.         if (string.equals ("noun"))
  120.             {
  121.                 string.replace("noun", nouns.getIndex(resultIndex));
  122.             }  
  123.             resultIndex++;
  124.            
  125.         }
  126.  
  127.     if (string.equals("noun"))
  128.     {
  129.            System.out.println("string" + subNoun(string, nouns));
  130.             return subNoun(string, nouns);
  131.         }  
  132.  
  133.     if (string.equals("verb"))
  134.     {
  135.         return subVerb(string, verbs);
  136.     }
  137.    
  138.           if(string.equals("adjective"))
  139.           {
  140.                         return subAdj(string, adjs);
  141.                     }
  142.                
  143.                     return string;
  144.                 }*/
  145.                
  146.  /*public String generate(randomNouns, randomVerbs, randomAdjectives)
  147.     {
  148.         randomNouns = new Random();
  149.         randomVerbs = new Random();
  150.         randomAdjectives = new Random();
  151.     }*/
  152. }