Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. /**
  2. * TODO Write a one-sentence summary of your class here. TODO Follow it with
  3. * additional details about its purpose, what abstraction it represents, and how
  4. * to use it.
  5. *
  6. * @author TODO Your Name
  7. * @version TODO Date
  8. *
  9. * @author Period - TODO Your Period
  10. * @author Assignment - JMCh10 Lipogrammer
  11. *
  12. * @author Sources - TODO list collaborators
  13. */
  14. public class LipogramAnalyzer
  15. {
  16. private String text;
  17.  
  18.  
  19. private int wordBeginning = 0;
  20. private int wordEnd = 0;
  21. private int wordJump;
  22.  
  23.  
  24. /**
  25. * Constructor: Saves the text string
  26. *
  27. * @param text
  28. * String to analyze
  29. */
  30. public LipogramAnalyzer( String text )
  31. {
  32. this.text = text;
  33. // TODO your constructor code here
  34. }
  35.  
  36.  
  37. /**
  38. * Returns the text string with all characters equal to letter replaced with
  39. * '#'.
  40. *
  41. * @param letter
  42. * character to replace
  43. * @return text string with all characters equal to letter replaced with '#'
  44. */
  45. public String mark( char letter )
  46. {
  47. String replacedString = text.replace( "e", "#" );
  48.  
  49. return replacedString; // !!!Fix this
  50. }
  51.  
  52.  
  53. /**
  54. * Returns a String that concatenates all "offending" words from text that
  55. * contain letter; the words are separated by '\n' characters; the returned
  56. * string does not contain duplicate words: each word occurs only once;
  57. * there are no punctuation or whitespace characters in the returned string.
  58. *
  59. * @param letter
  60. * character to find in text
  61. * @return String containing all words with letter
  62. */
  63. public String allWordsWith( char letter )
  64. {
  65. String result = "";
  66. //for (int i = 0; i < extractWord( ).length; )
  67.  
  68. while (wordEnd <= text.length())
  69. {
  70. for (int i = 0; i <= extractWord(wordEnd).length(); i++)
  71. {
  72. if (Character.isLetter( letter ) )
  73. {
  74. result += extractWord(wordEnd) + "\n";
  75. wordEnd += wordJump;
  76. }
  77. else
  78. {
  79. wordEnd += wordJump;
  80. }
  81. }
  82.  
  83. }
  84.  
  85.  
  86. return result;
  87. }
  88.  
  89.  
  90. // made public for test purposes
  91. /*
  92. * Returns the word that contains character at pos excluding any punctuation
  93. * or whitespace.
  94. *
  95. * @param pos location of character
  96. *
  97. * @return word that contains character at pos
  98. */
  99. public String extractWord( int pos )
  100. {
  101. // TODO your code here
  102.  
  103.  
  104. for ( int i = 0; i < text.length(); i++ )
  105.  
  106. {
  107. if ( Character.isWhitespace( text.charAt( i ) ) )
  108. {
  109. wordEnd = i;
  110. break;
  111. }
  112. }
  113.  
  114. int k = 0;
  115. //int pos2;
  116. for ( k = wordEnd; k >= 0; k--)
  117. {
  118. if ( Character.isWhitespace( text.charAt( k ) ) )
  119. {
  120. wordBeginning = k;
  121. break;
  122. }
  123.  
  124. }
  125.  
  126. wordJump = wordEnd - wordBeginning;
  127.  
  128. String extractedWord = text.substring( wordBeginning, wordEnd );
  129.  
  130. return extractedWord; // !!!Fix this
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement