Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are some basic mistakes here that you'll need to sort out before you can go any further.</p> <p>Let's look at this method first.</p> <pre><code>public HashSet&lt;String&gt; getWordSet(){ HashSet&lt;String&gt; set = new HashSet&lt;String&gt;(); for (String words : quoteOne){ words.add(word); } return words; } </code></pre> <p>Now, you haven't set <code>quoteOne</code> to anything yet, at least not in this class. And what you want it to be is the return value from calling <code>getWordArray()</code>. So it would be good to include the line</p> <pre><code>String[] quoteOne = getWordArray(); </code></pre> <p>somewhere in this method.</p> <p>Next, you're trying to reuse a variable name. You've already got <code>words</code> in this class, so to avoid confusion, it would be better if you use a different name for the <code>String</code> variable that you iterate through the loop with.</p> <p>Now, you're trying to add strings to <code>words</code>, when you actually want to add them to <code>set</code>, because <code>set</code> is the thing that you'll be returning from this method. So as well as changing the line with <code>add</code>, you'll also want to change the line with <code>return</code>, to make everything match. </p> <p>So think very carefully about what each variable is for, and make sure that you use each of them correctly. Some of these types of errors will be caught by the compiler, but that's not an excuse for being sloppy with your use of variables.</p> <p>There are actually shorter ways of turning an array into a <code>HashSet</code>, but I think it would be a good exercise if you try to get it correct, using this way of doing it first.</p> <p>Now let's look at the next method.</p> <pre><code>public HashMap&lt;String, Integer&gt; getWordCounts() { HashMap&lt;String, Integer&gt; map = new HashMap&lt;String, Integer&gt;(); for (String words : words) { words.add(word); } return HashMap&lt;String, Integer&gt;; } </code></pre> <p>You've got the right basic idea, but you're missing a couple of key steps. Firstly, just like in the previous method, you'll need a call to <code>getWordArray()</code>. But now, you need one more step. </p> <p>As you iterate through the loop, you'll need to look in the <code>HashMap</code>, using the <code>get</code> method, to see if a particular word has already been recorded there. If so, you'll need to see what <code>Integer</code> has been recorded against it, add one, then put it back in the map. If not, you can just put something into the map without doing any arithmetic.</p> <p>Also, please be aware that the method for adding things to any sort of map isn't <code>add</code>, it's <code>put</code>, and it needs two arguments - the key and the value. So at some point in your logic, you might have a line like</p> <pre><code>map.put(word, 1); </code></pre> <p>You can see the key and the value in this call.</p> <p>Lastly, think about your <code>return</code> statement. You want to return a variable, not its type. Can you guess which variable you'll use there?</p> <p>Good luck with finishing your assignment. I've tried to point you in the right directions without doing too much of this for you.</p>
    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.
 

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