WORD FREQUENCIES Input Standard Input Output Standard Output  Data Structure List   Problem Description Write a JAVA program that will display all words from a given passage with its frequencies. At the end of output, print the text analysis such as (i) Total words, (ii) Number of Repeated words, (iii) Number of Unique words and (iv) Most used word. Input Input of this program is a passage. A passage consists of N words and symbols. Symbols that will be considered in the passage are full stop (.), comma (,), question mark (?) and exclamation mark (!).  The passage will have M unique words, where the M is less than or equal to N. Output Output of the program is M lines, where each line contains a word followed by symbol (, then followed by an integer that represent the word frequency and ends by symbol). Display the analysis of Total words, Number of repeated words, Number of unique words and Most used word as shown in Sample InputOutput.   Sample Input-Output Input Output I go to school by bus. The bus is big. The school is also big. I like big school and big bus.   I(2) The(2) also(1) and(1) big(4) bus(3) by(1) go(1) is(2) like(1) school(3) to(1)     Total words: 22 Number of repeated words: 6 Number of unique words: 12 Most used word:  big     Solution The algorithm for Words Frequencies: Read a passage For each word in the passage: Search for the same word in the list If not found: Add the word into the list Set and add the word’s frequency to 1 If found:                 Update the word’s frequency value in list        Sort the list        Display the list and text analysis                     Class Data ** You must use class Data to complete the question 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 import   public                                                                                 }  java.util.Comparator; // Class Data  class Data { String word; int freq;  public Data (String item){         this.word =item;           this.freq=1;         }  public String getWord() { return word; }  public void setWord(String newword) {        this.word= newword; }  public int getFreq() {        return freq; }     public void setFreq(int freq2) {        this.freq = freq2; }  public static Comparator WordComparator = new Comparator() {      // Used for sorting in ascending order of word     public int compare(Data a, Data b)      {       String word1 = a.getWord();            String word2 = b.getWord();                     return (word1).compareTo(word2); //string1.compareTo(string2)     }  };

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

WORD FREQUENCIES

Input

Standard Input

Output

Standard Output 

Data Structure

List

 

Problem Description

Write a JAVA program that will display all words from a given passage with its frequencies. At the end of output, print the text analysis such as (i) Total words, (ii) Number of Repeated words, (iii) Number of Unique words and (iv) Most used word.

Input

Input of this program is a passage. A passage consists of N words and symbols. Symbols that will be considered in the passage are full stop (.), comma (,), question mark (?) and exclamation mark (!). 

The passage will have M unique words, where the M is less than or equal to N.

Output

Output of the program is M lines, where each line contains a word followed by symbol (, then followed by an integer that represent the word frequency and ends by symbol). Display the analysis of Total words, Number of repeated words, Number of unique words and Most used word as shown in Sample InputOutput.

 

Sample Input-Output

Input

Output

I go to school by bus. The bus is big. The school is also big. I like big school and big bus.

 

I(2) The(2) also(1) and(1) big(4) bus(3) by(1) go(1) is(2) like(1) school(3)

to(1)

 

 

Total words: 22

Number of repeated words: 6

Number of unique words: 12

Most used word:  big

 

 

Solution

The algorithm for Words Frequencies:

Read a passage For each word in the passage:

Search for the same word in the list If not found:

Add the word into the list

Set and add the word’s frequency to 1 If found:

                Update the word’s frequency value in list

       Sort the list

       Display the list and text analysis

 

 

 

             

Class Data

** You must use class Data to complete the question

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

import  

public

 

 

 

 

 

 

 

 

 

       

     

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

}

 java.util.Comparator;

// Class Data  class Data { String word; int freq;

 public Data (String item){         this.word =item;

          this.freq=1;

        }

 public String getWord() {

return word;

public void setWord(String newword) {        this.word= newword;

public int getFreq() {

       return freq;

}    

public void setFreq(int freq2) {        this.freq = freq2;

public static Comparator<Data> WordComparator = new Comparator<Data>() { 

    // Used for sorting in ascending order of word     public int compare(Data a, Data b) 

    { 

     String word1 = a.getWord();

           String word2 = b.getWord();

           

        return (word1).compareTo(word2); //string1.compareTo(string2)

    } 

};

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY