Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2011
    Rep Power

    Default 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

    scrambled (2):
    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!!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: Read in File and Store it in an Array. Please Help!

    Quote Originally Posted by PurpleDemon666 View Post
    I have no idea what I am doing and would be greatly pleased if someone could help me. Thank You!!
    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.

Similar Threads

  1. Store links in text file and read into variables
    By africanhacker in forum New To Java
    Replies: 1
    Last Post: 03-31-2011, 05:18 PM
  2. Need a solution to read and store data from a file
    By sheetalnri in forum New To Java
    Replies: 10
    Last Post: 09-30-2010, 06:43 AM
  3. store data into an array from a file
    By chopo1980 in forum New To Java
    Replies: 10
    Last Post: 11-13-2009, 09:48 AM
  4. Replies: 5
    Last Post: 07-30-2008, 09:30 AM
  5. Replies: 3
    Last Post: 04-07-2008, 06:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts