Unit 6 Lesson 6 part 7a (customer review) incorrect

The Example solution is incorrect. You should not parse the responses by finding " ". It will fail to match “great” with “great!”. If you run the example solution, it says the word great exists 2 times in the first response, but it actually exists 3 times.
The suggested algorithm is fundamentally flawed. You should use indexOf() until you get a -1 (chopping the string down each time). It’s easier, less code, and more straightforward.
EG:

   ArrayList<Integer> result = new ArrayList<Integer>();
    
    for (String r : reviews)
    {
      int count=0;
      int i = r.indexOf(wordToFind);
      while(i>-1)
      {
            count++;
            r=r.substring(i+1);
            i=r.indexOf(wordToFind);
      }
      result.add(new Integer(count));
    }
    return result;

This means that what I think is correct, will not pass the test…or am I missing something?

1 Like

Hi Timothy, thanks for your post about this lesson! I noticed the same issue as I did this lesson withmy class. I live coded this level with my students and we got it working using the suggested algorithm just checking for the spaces. We then noticed the great! that didn’t get added to the tally and discussed what we would need to look for in terms of punctuation to store just the words and no punctuation, and also considered the use of .toLowerCase() to account for capitalization differences. Some of my students went through and added that functionality as part of their unit 6 projects. The fully working version then doesn’t meet the tests, but also is a much more complicated algorithm. Please use the rate this lesson button on the unit overview page to give your feedback on this to the curriculum team.

Thank you,
Lindsay

2 Likes

But the correct way is to not break the reply into “words”. You just need to count the number of indexOf (chopping the reply down as I did in my example). It’s actually quite simple (simpler than the example solution). It’s also the standard way it’s done on the AP Test…although there are other functions/methods in the String class that would make this even easier.
I don’t mind their being issues with code.org’s code, but I do take issue with code.org encouraging flawed logic. Their algorithm is not correct. That said, I will do as you suggest and use the “rate this lesson”. Thanks.

Thank you, Timothy for passing that code and your thoughts onto the curriculum team using the rate the lesson button. And for posting here, it gives other teachers who are prepping for this lesson the heads up about this level. This curriculum is improved each year, and teacher feedback like yours is helpful in that endeavor!

Best,
Lindsay

1 Like