Due Friday, 2/10 - 5:00pm
1. Implement a program that provides search-and-replace functionality. Allow the user to specify a search term, a replace term, and a file name. Open the file, replace all instances of the search term with the replace term and save the result to a new file. You may choose the name of the new file. You may implement the logic of this program in the main method of a single class
2. Create a Java Project called Sorter.
- Create a class called WordCount.
- Define a data member of type String called theWord and a data member of type int called count.
- Implement a constructor that will take as input a String and store the value in the data member theWord and will initialize count to 0.
- Implement a method getWord that will take no input and will return the the value of theWord.
- Implement a method increment that will take no input and will increase the value of count by 1.
- Implement a method toString that will take no input and will return a string containing "Word: " followed by the value of theWord, followed by "Count: " followed by the value of count (e.g., Word: walk Count: 15)
- Create a class called SortedWordList.
- Define a data member of type ArrayList of WordCount called words.
- Implement a constructor that will initialize the words data member.
- Implement a method addAndIncrement that will take as input a string and will add it to the ArrayList maintaining the list in sorted order. You must implement the sorting yourself. If word already appears in the list, you will increment the count of the word.
- Implement a method display that will display the each WordCount item in the list. For each item, invoke the toString method of the WordCount object.
- Create a class SortedWordListDriver that contains a main method that will prompt the user for a file name, open the file, add each word from the file into a SortedWordList object, and then print all words in the SortedWordList object.
- Make sure to test this program on several sample input files. You may create a few small files of your own, but you should also test using dracula.txt attached below. Your program make take several seconds to run on dracula.txt unless you have implemented a binary search algorithm.
Submission Instructions
Please submit your work in an SVN directory https://www.cs.usfca.edu/svn/<username>/cs112/lab3.