Tags:
tag this topic
create new tag
view all tags
---+ Eighth lab: Arrays and counting key words ---++ Learning Objective(s) 1. Learn to use one dimensional arrays 1. Learn to use command line arguments 1. 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 <b>WordCounter</b> * 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: <pre>public class int double </pre> ---+++Second file: (note: no punctuation) <pre>public class Demo public static void main String args int a public return </pre> ---+++Output file <pre> 3 public 1 class 1 int 0 double </pre> ---++ Submission 1 Create an empty zip folder. 1 Place your program (.java file) in it 1 Place your software development report in it. 1 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 1. 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 1. 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 1. Change it so that there can be multiple words in a line 1. Add exception handling code whenever you feel comfortable. Also deal with the upper/lower case issue when you feel comfortable 1. Change the "counting" routine to look up each word from the second file in the array, printing out the location. 1. Add additional data structures to store counters and make the code do everything (except getting the filenames from the command line arguments) 1. Add in command line arguments
E
dit
|
A
ttach
|
Watch
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2022-03-11
-
cathybareiss
Home
Site map
Assessment web
BethelAIResources2026 web
CenterForComputing web
ChatGPT web
Intro2AIatBethel web
Main web
Sandbox web
TWiki web
CenterForComputing Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Register User
E
dit
A
ttach
Copyright © 2008-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback