Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've changed your code to work:</p> <pre><code>import java.util.*; import java.lang.Iterable; public class Main { String words; public static void main(String[] args) { Main plato = new Main( "You can discover more about a person in an hour of play than in a year of conversation"); Main roosevelt = new Main( "When you play play hard when you work dont play at all"); String[] platoArray = plato.getWordArray(); String[] rooseveltArray = roosevelt.getWordArray(); plato.printArray(platoArray); roosevelt.printArray(rooseveltArray); System.out.println("____________________________________________________"); HashSet&lt;String&gt; rooseveltWordSet = roosevelt.getWordSet(platoArray); roosevelt.printArray(rooseveltWordSet); System.out.println("____________________________________________________"); roosevelt.printArray(roosevelt.getWordCounts()); System.out.println("____________________________________________________"); } public Main(String word) { words = word.toLowerCase(); } protected String[] getWordArray() { String[] wordArray = words.split(" "); return wordArray; } protected HashSet&lt;String&gt; getWordSet(String[] groupedWords) { HashSet&lt;String&gt; wordSet = new HashSet&lt;String&gt;(); for (String string : groupedWords) { wordSet.add(string); } String[] wordArray = getWordArray(); for (String string : wordArray) { wordSet.add(string); } return wordSet; } protected void printArray(String[] array) { for (String string : array) { System.out.println(string); } } protected void printArray(HashSet&lt;String&gt; hashWords) { for(String hashset: hashWords) { System.out.println(hashset); } } /*Changed*/ protected void printArray(HashMap&lt;String, Integer&gt; printHashMap) { for(String string: printHashMap.keySet()) { System.out.println(string + ":" + printHashMap.get(string) ); } } /*changed*/ protected HashMap&lt;String, Integer&gt; getWordCounts() { String[] wordArray = getWordArray(); HashMap&lt;String, Integer&gt; wordCounts = new HashMap&lt;String, Integer&gt;(); for(String string: wordArray) { if(wordCounts.containsKey(string)){ wordCounts.put(string, wordCounts.get(string) + 1); }else{ wordCounts.put(string, 1); } } return wordCounts; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload