Results 1 to 2 of 2
- 10-21-2011, 06:38 PM #1Member
- Join Date
- Oct 2011
- Rep Power
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!
- By africanhacker in forum New To JavaReplies: 1Last Post: 03-31-2011, 05:18 PM
- By sheetalnri in forum New To JavaReplies: 10Last Post: 09-30-2010, 06:43 AM
- By chopo1980 in forum New To JavaReplies: 10Last Post: 11-13-2009, 09:48 AM
- By szimme101 in forum New To JavaReplies: 5Last Post: 07-30-2008, 09:30 AM
- By szimme101 in forum Advanced JavaReplies: 3Last Post: 04-07-2008, 06:02 PM