reset password
Author Message
RandomAccess
Posts: 101
Posted 23:55 Sep 20, 2018 |

I'm having trouble understanding one of the directions. Specifically the following -

A recursive filter method that takes a list of Strings and returns the following:

/*

  • if all of the Strings in the list are contained in the list of valid words, return a single String made up of the Strings in the order in which they appear in the list
  • if any of the Strings in the list do not appear in the list of valid words, return null. This should be much more common than the first case.

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

*/

The assignment says we should print all of the anagrams that match a word in the text file, but these seem to suggest that you should only print them if all of the anagrams are valid words, and that you should return null otherwise. Am I missing something? please help me understand it you can.

jhurley
Posts: 207
Posted 06:37 Sep 21, 2018 |
RandomAccess wrote:

I'm having trouble understanding one of the directions. Specifically the following -

A recursive filter method that takes a list of Strings and returns the following:

/*

  • if all of the Strings in the list are contained in the list of valid words, return a single String made up of the Strings in the order in which they appear in the list
  • if any of the Strings in the list do not appear in the list of valid words, return null. This should be much more common than the first case.

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

*/

The assignment says we should print all of the anagrams that match a word in the text file, but these seem to suggest that you should only print them if all of the anagrams are valid words, and that you should return null otherwise. Am I missing something? please help me understand it you can.

You are going to run this method on *each* anagram in the list of anagrams. Use String.split() to break the one anagram into a list of Strings. If all the Strings in the list are in the word list, then the anagram consists entirely of valid ENglish words. In that case, combine them back into one long String and return it. Otherwise, the anagram does not consist entirely of valid English words; in that case, return null.

dtang9
Posts: 52
Posted 09:54 Sep 21, 2018 |

I moved my question to another topic.

Last edited by dtang9 at 14:08 Sep 21, 2018.
RandomAccess
Posts: 101
Posted 12:27 Sep 21, 2018 |

OH, I get it, this is to read every individual word contained in each anagram in case the original string contained a space or spaces that would divide some of the anagrams into two or more words?

jhurley
Posts: 207
Posted 13:08 Sep 21, 2018 |
RandomAccess wrote:

OH, I get it, this is to read every individual word contained in each anagram in case the original string contained a space or spaces that would divide some of the anagrams into two or more words?

yes

RandomAccess
Posts: 101
Posted 15:06 Sep 21, 2018 |

Another question, I know the recursive filter method can't use a loop, but can it call another outside method?

jhurley
Posts: 207
Posted 15:27 Sep 21, 2018 |
RandomAccess wrote:

Another question, I know the recursive filter method can't use a loop, but can it call another outside method?

as long as the recursion works as described

RandomAccess
Posts: 101
Posted 16:02 Sep 21, 2018 |

Thanks, you've all been a big help

dtang9
Posts: 52
Posted 15:09 Sep 23, 2018 |

For an anagram like "cab", does filter take the argument of the list containing: "c", "a", "b" ?  In the filter method, I am confused on how to compare this list with the list of valid words. I tried getting each word in the entire list of valid words and comparing it with my anagram string by string because there is no loop counter.

EDIT: This is wrong. I fixed my code. Question answered.

Last edited by dtang9 at 19:21 Sep 24, 2018.