Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * TODO Write a one-sentence summary of your class here. TODO Follow it with
- * additional details about its purpose, what abstraction it represents, and how
- * to use it.
- *
- * @author TODO Your Name
- * @version TODO Date
- *
- * @author Period - TODO Your Period
- * @author Assignment - JMCh10 Lipogrammer
- *
- * @author Sources - TODO list collaborators
- */
- public class LipogramAnalyzer
- {
- private String text;
- private int wordBeginning = 0;
- private int wordEnd = 0;
- private int wordJump;
- /**
- * Constructor: Saves the text string
- *
- * @param text
- * String to analyze
- */
- public LipogramAnalyzer( String text )
- {
- this.text = text;
- // TODO your constructor code here
- }
- /**
- * Returns the text string with all characters equal to letter replaced with
- * '#'.
- *
- * @param letter
- * character to replace
- * @return text string with all characters equal to letter replaced with '#'
- */
- public String mark( char letter )
- {
- String replacedString = text.replace( "e", "#" );
- return replacedString; // !!!Fix this
- }
- /**
- * Returns a String that concatenates all "offending" words from text that
- * contain letter; the words are separated by '\n' characters; the returned
- * string does not contain duplicate words: each word occurs only once;
- * there are no punctuation or whitespace characters in the returned string.
- *
- * @param letter
- * character to find in text
- * @return String containing all words with letter
- */
- public String allWordsWith( char letter )
- {
- String result = "";
- //for (int i = 0; i < extractWord( ).length; )
- while (wordEnd <= text.length())
- {
- for (int i = 0; i <= extractWord(wordEnd).length(); i++)
- {
- if (Character.isLetter( letter ) )
- {
- result += extractWord(wordEnd) + "\n";
- wordEnd += wordJump;
- }
- else
- {
- wordEnd += wordJump;
- }
- }
- }
- return result;
- }
- // made public for test purposes
- /*
- * Returns the word that contains character at pos excluding any punctuation
- * or whitespace.
- *
- * @param pos location of character
- *
- * @return word that contains character at pos
- */
- public String extractWord( int pos )
- {
- // TODO your code here
- for ( int i = 0; i < text.length(); i++ )
- {
- if ( Character.isWhitespace( text.charAt( i ) ) )
- {
- wordEnd = i;
- break;
- }
- }
- int k = 0;
- //int pos2;
- for ( k = wordEnd; k >= 0; k--)
- {
- if ( Character.isWhitespace( text.charAt( k ) ) )
- {
- wordBeginning = k;
- break;
- }
- }
- wordJump = wordEnd - wordBeginning;
- String extractedWord = text.substring( wordBeginning, wordEnd );
- return extractedWord; // !!!Fix this
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement