Eighth lab: Arrays and counting key words
Learning Objective(s)
- Learn to use one dimensional arrays
- Learn to use command line arguments
- Continue to improve skills working with files
Overview of the program
This lab should count the number of occurrences of different key words in a file.
Details
- Input:
- The first command line argument is a text file with all the key words in it. The words are separated by white space. The file can be multiple lines
- The second command line argument is a text file with all sorts of words in it (multiple lines with multiple words per line). This is the file that is to be "counted".
- You may assume there are no punctuation marks or numbers in either file. You are to ignore the differences between upper and lower case.
- Restrictions
- You may only read each file once.
- Output
- For each key word specified in the first file, there should be a line of output specifying the number of times (0 to n) it occurred in the second file.
- The output should be sent to a file specified by the third command line argument
- The program should be called WordCounter
- You need to have at least one method besides the main method.
- You must use at least one constant
- You must use arrays as your primary storage
- There will not be more than 1000 key words in the first file
- All normal exceptions should be handled (not thrown)
- Hints are at the end. I suggest you consider trying to solve without the hints. But they are there if you need/want them.
Sample "dialogue"
First file:
public class
int double
Second file: (note: no punctuation)
public class Demo
public static void main String args
int a public
return
Output file
3 public
1 class
1 int
0 double
Submission
- Create an empty zip folder.
- Place your program (.java file) in it
- Place your software development report in it.
- Submit the zip folder on canvas
Optional improvements
none this time
Hints/suggestions
Below are the steps I would recommend to take in solving the problem. Get each step to work correctly before moving on
- Have one key word (which can be inputted from the keyboard or a literal) and search a file (specified by a literal) for the number of times that keyword exists
- Add code before that to read in words from a file into an array (file specified by a literal). Assume there is one word per line. Then count the number of occurrences of the first word in the array in the second file
- Change it so that there can be multiple words in a line
- Add exception handling code whenever you feel comfortable. Also deal with the upper/lower case issue when you feel comfortable
- Change the "counting" routine to look up each word from the second file in the array, printing out the location.
- Add additional data structures to store counters and make the code do everything (except getting the filenames from the command line arguments)
- Add in command line arguments