IndexBuilder takes a source file and the array of words to index and finds all o
ID: 3640656 • Letter: I
Question
IndexBuilder takes a source file and the array of words to index and finds all of the occurrences of each word in the file. Write a IndexBuilder that takes a file object named sourceFile and a String[] object named indexWords as constructor arguments.*The constructor should read the file line-by-line. As it reads each line, it should collect the following statistics:
*The total number of words and lines in the file.
* The lines where each index word appears - ignoring case and accounting for lines where an index word may appear more than once.
*You should only have to read each file once if you are doing this program properly.
* Write accessor methods as defined by the Interface for the number of words, number of lines, and for the arrays containing lines where each word was found.
* Write a toString() method that can be printed to summarize the statistics for the file.
Explanation / Answer
please rate import java.io.File; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Scanner; public class IndexBuilder { int no_of_lines_in_file = 0; int no_of_words = 0; List lines_with_index_words = new LinkedList(); public IndexBuilder(File sourceFile,String[] indexWords){ try{ Scanner getLine = new Scanner(sourceFile); while(getLine.hasNextLine()){ int flag=0; no_of_lines_in_file ++; String line = getLine.nextLine(); Scanner getWord = new Scanner(line); while(getWord.hasNext()){ no_of_words ++; String word = getWord.next(); for(int i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.