Java I CS 142 Week 05 Assignment.docx

advertisement
Java I CS 142 Week 05 Assignment
Your job will be to write a program that can find a needle in a haystack:
1. Classname= “Week05”
2. As always, the first line of code should have your name in a comment, and the first output your
program produces should also display your name.
3. Your program will ask the user three things:
a. The fully-qualified file specification of a file to search. (I recommend using “Chooser” to
do this. Look it up in the index of the book, or Google it).
b. Whether the search is to be case-sensitive or not.
c. A string to search.
4. Your program will open the file the user has specified, and read it on a line-by-line basis.
5. When or if your program encounters the “search string” in the file, it will display the line
number and location in the line where the search string was found.
6. Your program will create a new file specification, identical to the original input file spec, but with
“.txt” pospended (appended to the end: if the original filespec was:
C:\users\dave\my documents\happy_time.java, the output new file spec should be:
C:\users\dave\my documents\happy_time.java.txt.
7. Your program will open the output filespec developed in line 6, for output. It will put in that file
text like:
Opened “C:\users\dave\my documents\happy_time.java” for input
Found the string “needle” in position 12 of line 133
(or)
Did not find the string “needle” in the file.
The search was or was not case sensitive.
8. Submit your .java file to the OIS dropbox. Click on the “OIS” icon next to CS142 in “My Classes”
in the portal. For full credit, it is due at noon, on Sunday, February 5th. It may be submitted up
to one week late for reduced credit.
Some extra credit opportunities:
1. Use the Eclipse Window builder rather than using JOptionPane. If you do this, there should be
an input field on the window for the user to type the text to be searched for, an input text field
for the file specification of the file to read, a “…” button to invoke Chooser (and fill in the
filespec field, a “Find It” button, a check box for the user to indicate whether the search is to be
case sensitive or not, and a label field which will display answers.
2. Open a third file, with extension “.fixed”, which should be a copy of the input file with each
occurrence of the search string substituted to a different string specified by the user.
3. Note to get extra credit, you must claim it three ways: in the Title and Description fields of the
Dropbox, and the program should display (Console or GUI) the claim of extra credit.
Java I CS 142 Week 03-04 Assignment
p. 1 of 2
Java I CS 142 Week 03-04 Assignment
p. 2 of 2
Download