java · level 3 check

a concurrent word counter.

Time to ship a real tool: a word counter. The first line typed says how many top words to show, from 1 to 20. Every line after it is text. The tool counts each line as its own job on a thread pool, then prints a sorted report.

Make it robust. The two patterns in `wordsIn` keep only letters and apostrophes, then trim stray quote marks, so `Cat,` and `cat` count together and `don't` stays whole. A bad first line, like `lots`, gets a clear error instead of a crash, and text with no words says so.

Lines finish in any order, so their counts merge into one `ConcurrentHashMap`, and the report sorts by count, highest first, then alphabetically. That keeps the output identical on every run. Fill in each `____`, then try it on your own text.

Fill in every ____ then run the checks.
  1. 1 It counts every word on every lineuses: streams
  2. 2 It ranks by count, then alphabeticallyuses: comparators
  3. 3 It ignores capitals and punctuationuses: text
  4. 4 It keeps words like don't wholeuses: text
  5. 5 It refuses a bad first lineuses: Optional
  6. 6 It copes with text that has no wordsuses: edge cases

Take as long as you like and try as many times as you want.