Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I am having much trouble writing a nested loop to iteratethough a text fi

ID: 3613975 • Letter: H

Question

Hello, I am having much trouble writing a nested loop to iteratethough a text file, scan for words and then output another filecontaining on each line the word followed by a colon and itsfrequency (e.g., word : 10).

What I have is 2 classes, one is the Vector class:

public class Count
{
public String word;
public int count;

public Count(String word, int count)
{
this.word = word;
this.count = count;
}
}
The second class uses myReader.readLine() -- and -- BufferedReadermyReader = new BufferedReader(new FileReader(fileName)); -- to readin a line at a time and uses:
private Vector<Count> wordCounts //to store vectorobjects
as well as using line.split("\W+") to split a line into words.
I am able to read and split the text box into separate words, but Iam having a heck of a time of creating a loop that will read a wordand the scan the paragraph for its duplicates.
Thanks in advance.

public class Count
{
public String word;
public int count;

public Count(String word, int count)
{
this.word = word;
this.count = count;
}
}

Explanation / Answer

scan for words and then output another filecontaining on each line the word followed by a colon and itsfrequency (e.g., word : 10). What do you mean by this... please be specific. I didn't really getit. @your concept: If you are able to separate words from text box, dothe same for paragraph: separate them into some kind of tokens witheach word, trim it for any leading or ending spaces and compare itwith word from textbox.