mostCommonNames
Write a method mostCommonNames
that accepts a Scanner
for an input file with names on each line separated by spaces. Some names appear multiple times in a row. For example:
Benson Eric Eric Marty Kim Kim Kim Jenny Nancy Nancy Nancy Paul Paul Stuart Stuart Stuart Ethan Alyssa Alyssa Helene Jessica Jessica Jessica Jessica Jared Alisa Yuki Catriona Cody Coral Trent Kevin Ben Stefanie Kenneth
For each line, print the most commonly occurring name. If there's a tie, use the first name that had that many occurrences.
Most common: Kim Most common: Jessica Most common: Jared
Also return the total number of unique names in the whole file (e.g. 23 for the above input).