Question: sortList Method: implement INSERTION SORT to sort the list that is passed as a parameter. NOTE: no need to return a list because the list
sortList Method: implement INSERTION SORT to sort the list that is passed as a parameter.
NOTE: no need to return a list because the list passed as a parameter is a reference object.
By using only provided method.
Do not use: import java.util.Collections;
Description
Write a Java program to read data from a text file file name given on command line process
the text file by performing the following:
Print the total number of words in the file.
Print the total number of unique words case sensitive in the file.
Print all words in ascending order without duplication, ie all unique words.
Print all lines with line numbers of the file where a specific phrase is found.
You must prompt the user to enter a specific phrase to search for. Under each
output line indicate the locations of the first character of the matched phrase
refer to the Sample Output below
After outputting results keep prompting user until the user enters EINPUT short
for "end input"
A few example files are provided including randomtest.txt easiertest.txt and javatest.txt
Requirements
You are allowed to use Java ArrayList to implement your solution.
The Java source file must be formatted with proper indentation.
You must enter a javadoc comment before the class declaration. In the comment you
must provide a small description of this program followed by your name.
a For example, my class would be:
Project is a program toput your description here...
@author Mark Gonzales
public class Projectmgonzales
You must enter a javadoc comment before EACH method declaration. In the comment
you must provide a small description of this method, specify the parameters and what the
method returns. Follow the template below:
@param
@return
You must handle all Checked Exceptions appropriately:
a Must output an appropriate message.
b Must put the program into a state in which the user can recover from or exit if
necessary.
There must be at a minimum the following methods:
apts Name: main
i Desaription: The main method should do the following.
Retrieve the file name from the command line.
The program should exit if the file does not exist or if the file name
is not given on the command line. When exiting the program
should print the message "File does not exist."
If the file exists the main method should call the processFile
method. Any data that is needed from the main method must be
passed to the processFile method via its parameters. See
processFile method below.
bpts Name: processFile
i Dessription: The processFile method should do the following:
a Read contents from the file.
b Print the total number of words in the file.
c Print the total number of unique words case sensitive in
the file. In order to do part c you must call the
createUniqueList method.
d Print all words in ascending order without duplication. In
order to do part d you must call the sortList method.
Once the information above is printed to the console the processFile
method should call the search method. Any data that is needed from the
processFile method must be passed to the search method via its
parameters.
c pts Name: createUniqueList
i Deszription: The createUniqueList method should receive as input a List
of words that are not unique, ie there are duplicate words in the List. The
method must create a new List by adding only unique words from the
input List.
Parameter
a Name: wordList
b Type: ArrayList
c Description: a list that has duplicate words
Return
a Type: ArrayList
b Description: a list of nonduplicate words
d pts Name: sortList
i Dessription: The sortList method should receive as input a List of
unsorted words. The sortList method should modify the unsorted List into
a sorted List. You must implement a sort algorithm. You can choose any
sorting algorithm you want. Do not use a buil: in Java method to sort the
list.
Parameter
a Name: uniqueWordList
b Type: ArrayList
c Description: a list of unsorted words
Return
a ArrayList
b Description: a list of sorted words
epts Name: search
i Dessription: The search method should prompt the user for a search
phrase. Given the search phrase the search method should search each line
in the file for the location of the phrase on each line. If the search phrase is
not found on a line then just go to the next line. The search method must
find every occurrence of the phrase on a line. The search method should
print the line number, the line and the location of the search phrase use
: After all lines have been searched the search method then prompts the
user to enter another search phrase. The search method does not exit until
the user enters the phrase EINPUT. See Sample Output.
Output, which assumes the
use of the randomtest.txt file as input.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
