Menu
support@nursinghomework.org
+1 714-215-3097

(Solved) : Using Java Create Anagramizer Takes Short Phrase Returns List Every Anagram Made Entirely Q35542679

  1. USING JAVA

    Create an Anagramizer which takes a short phrase and returns alist of every anagram that is made up entirely of valid Englishwords. Both the generation of the anagrams and the filtering stepwhich keeps only anagrams which consist of English words should bedone using recursion. There may be better ways to do these tasks,but this is an excerise in recursion.

    An anagram is a rearrangement of the characters in a string. Forexample, “way cool” is an anagram of “lacy woo”. Most definitionsallow you to add blank spaces arbitarily, but for this assignmentjust count any spaces that are part of the original String ascharacters in the String and don’t add more. Also, use the Stringtrim() method to drop spaces at the beginning or end of theanagrams; for example, “bait teas” will count as an anagram of “Ieat bats” since the additional space can migrate to the beginningor end and be trimmed. We will soon learn a way to removepunctuation, but it is acceptable to simply use input phrases thatdo not contain punctuation. Use the String toLowerCase() ortoUpperCase() on the input String, since ignoring case will createa larger number of meaningful anagrams.

    We will define “a valid English word” as one that is containedin the list of acceptable words for the board gameScrabble. This list is contained in the text filetwl06.txt, linked from the course web page. Download it an put itin your Eclipse project.

    Here are descriptions of some of the methods you will need:

  2. A method that parses the valid word file to a list of Strings.You may use a loop in the parsing method.
  3. A nonrecursive method that prints the input String, makes thefirst call to the recursive anagramizer method, sends the result tothe filter method, and prints the filtered result. You may use thiscode:private void anagramize(String inString) { System.out.println(“input string: ” + inString); List < String > l = filter(anagramizeRecursive(inString.toLowerCase())); System.out.println(“Anagrams: ” + l);} The code snippet above includes a declaration of a list of Strings.Your browser may not show the parameterizing type correctly becausethe angle braces make it look like an html tag.
  4. A recursive method that takes a String as its argument andreturns a list of Strings which includes all anagrams of theString. This method will contain a loop that generates eachpossible substring consisting of all but one character in the inputString, ie the substring that omits the first letter, then thesubstring that omits the second letter, etc. Within the loop, themethod calls itself recursively for each substring. For each Stringin the list returned by the recursive call, add the omittedcharacter back to the end and add the String to the list to bereturned. When the first instance of this method returns, the listwill contain all anagrams of the original input String. It may helpto work this out with a pencil and paper for a very short string(like “abc”.) The most straightforward base case (terminationcondition for the recursion) is to return a list containing only anew empty String if the input String has length 0. If you want achallenge, try replacing this algorithm with one that uses onlyrecursion, with no loops.
  5. A nonrecursive method that starts the recursion for thefiltering step. This method will take a list of Strings, consistingof the anagrams, as its argument. Use a loop that takes each Stringin the list, converts it to an array of Strings using String’ssplit() method with a blank space as the argument, and then usesthe array to provide values for a list of Strings. The result ofthis will be a list of Strings in which each String is a word fromthe anagram. Still inside the loop, call the recursive filtermethod for each of these Strings. In each case when it receives anon-null String as the return value fo the recursive filter method,it will add the String to the list which it returns.
  6. A recursive filter method that takes a list of Strings andreturns the following:
    • if all of the Strings in the list arecontained in the list of valid words, return a single String madeup of the Strings in the order in which they appear in thelist
    • if any of the Strings in the list do notappear in the list of valid words, return null. This should be muchmore common than the first case.

    If a list is received for which the last String isin the word list, this method should recursively call itself on alist consisting of all but the last word. If the recursive callreturns a String (not null), add the last word back to the end ofthe String and return it. This method should not containany loops.

    Don’t reparse the file each time, search the wordlist in memory.

    The word list contains some acronyms, loan words that are onlysemi-commonly used in English, and archaic words. Be careful whenyou are testing the filtering method.

  7. If you want a challenge, redesign the filtering and/oranagramizing step so that it does not use any loops at all. Youwill probably need to pass two lists (filter) or two Strings(anagramizer) as arguments to accomplish this.
  8. You may use JOptionPane I/O, a JavaFX GUI, or console(System.out.println and Scanner) IO. Turn in the .java files and anexecutable .jar file. You are not required to turn in JUnit tests,but it will probably be much easier to solve this problem correctlywith JUnit than by retyping input strings each time yourecompile.
  9. This application will be very computation-intensive, and thetime the anagram generation takes will increase dramatically witheach additional character. Test it with short strings like “waycool” and “fat cat”. Strings longer than that will take a long timeto process.

Leave a Reply

Your email address will not be published. Required fields are marked *