Read in File and Store it in an Array. Please Help!
I am very new to Java and programming is very frustrating for me. I have to take a programming course and one of the homework question is to make a basic search engine. Here is the prompt:
In this assignment, you'll build a simple search engine for the contents of a book.
To begin with, you'll need to construct an array that stores all of the distinct words (also called "word types") that are contained in a text file, which the user supplies the name of.
You'll also need to construct a data structure that stores all of the lines of text from the text file that contain each word type. These lines are the concordances of the word type.
Finally, the program should repeatedly prompt the user to enter a search term. For each search term, the program should display the number of times the word appears in the file, and the concordances (lines) for each appearance of that word. The user should be able to quit searching (and end the program) by entering "\\Quit".
For example, if the user supplies the text of The Adventures of Huckleberry Finn and then searches for the token "scrambled", the program should print
184 scrambled out of the window on to the shed. Then I slipped down to the
2638 So they started, and I lit out, all in a cold sweat, and scrambled
The following suggestions may or may not be helpful to you in your implementation:
To count the number of distinct words in a file, first read all of the words into a large array, then sort it (use Arrays.sort()), and then count how many distinct words are in the sorted array. Note that the number of distinct words is NOT the same as the total number of words (which is the length of the array).
You can also use this sorted array to count how often each distinct word appears in the file. That information could be stored in its own data structure.
To store all of the concordances, you will need a 2D array of Strings (or, if you prefer, an array of ArrayList objects)
I have no idea what I am doing and would be greatly pleased if someone could help me. Thank You!!
Re: Read in File and Store it in an Array. Please Help!
This assignment has several steps, each of which can be done first in isolation and then combined. I suggest you do just this, one step at a time, and then come back if you get stuck on any specific step. The fourth link in my signature links below titled "So, You Need To Write a Program..." will help you with these steps. I also recommend you have a face-to-face chat with your instructor.
Originally Posted by PurpleDemon666