Question: 1. Complete the method uniqueWords. Unique words should count the number of unique words in a text. Words that occur more than once should

  1. 1. Complete the method uniqueWords. Unique words should count the number of 

1. Complete the method uniqueWords. Unique words should count the number of unique words in a text. Words that occur more than once should only be counted one time. You will need to clean the data to obtain an accurate count. 2. Hyphenated words should be counted as one word. 3. Case should not matter. For example, "The" and "the" should only be counted once. 4. Numbers and punctuation should not count as words. However, words like its and it's should both be counted. 5. For example, the text for Time Machine should contain approximatly -4,660 unique words. 6. Main.java 7. import java.io.Buffered Reader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.Set; import java.util.TreeSet; import java.util.HashSet; import java.util.stream.Collectors; 8. class Main { 9. public static void main(String[] args) throws FileNotFoundException, IOException { String file = "TimeMachine.txt"; List list; try (Buffered Reader br = new Buffered Reader(new FileReader(file))) { list = br.lines().collect(Collectors.toList()); } 10. 11. } 12. public static int uniqueWords(List lines) { 13. return 0; 14. System.out.println("" + file.replace(".txt","")); System.out.println("Unique words: " + uniqueWords(list)); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!