Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

I am new to Java and don't know how to create a method for the 

$
0
0
This is what I've done so far! I have included comments to help you understand what I'm trying to do

/**
* This method should iterate over the {@link words} list and look for words
* that are anagrams of one another. The method should return a list of
* words which are anagrams, discarding the rest.
*
* For example, if the {@link words} list contains the words "act", "cat"
* and "dog" then the method should return a list containing "act" and
* "cat".
*
* 
* @param words
* a list of words to look through for anagrams
* @result a list of words which are anagrams of each other
*/
public static List<String> findAllAnagrams(List<String> words) {
/* TODO: Write the code for this method! */
return null;
}
}
public class Kata1 {
private static final String[] _WORDS = { "aardvark", "act", "bat", "cat",
"dent", "tab", "tac", "sat", "sad" };
private static final List<String> WORDS = new LinkedList<String>(
Arrays.asList(Kata1._WORDS));
private static List<String> result = null;
@Before
public void setUp() throws Exception {
Kata1.result = _Kata1.findAllAnagrams(Kata1.WORDS);
}
@Test
public final void testAnagrams() {
Assert.assertTrue(Kata1.result.contains("act"));
Assert.assertTrue(Kata1.result.contains("bat"));
Assert.assertTrue(Kata1.result.contains("cat"));
Assert.assertTrue(Kata1.result.contains("tab"));
Assert.assertTrue(Kata1.result.contains("tac"));
}
@Test
public final void testNotAnagrams() {
Assert.assertFalse(Kata1.result.contains("aardvark"));
Assert.assertFalse(Kata1.result.contains("dent"));
Assert.assertFalse(Kata1.result.contains("sat"));
Assert.assertFalse(Kata1.result.contains("sad"));
}
@Test
public final void testNotNull() {
Assert.assertNotNull(Kata1.result);
}
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>