Write a java program that will read a sequence of names (first name followed by last name, separated by at least one space) from a text file and will 1) remove all duplicate names and 2) write the names (last name followed by a comma, followed by one space, followed by first name) in ascending order to a text file.
For example, if the input file contains:
Colette Sapienza
Gretta Beumer
Emmanuel Mossman
Colette Sapienza
Shawanda Hutt
Adriana Montilla
Adriana Montilla
Adriana Montilla
Marica Stanfill
Neva Shover
Tijuana Means
Adriana Montilla
Gerri Koenig
Kirsten Beres
Kirsten Beres
The output file must contain:
Beres, Kirsten
Beumer, Gretta
Hutt, Shawanda
Koenig, Gerri
Means, Tijuana
Montilla, Adriana
Mossman, Emmanuel
Sapienza, Colette
Shover, Neva
Stanfill, Marica
Your program must contain and use the following methods:
public static int find
(ArrayList names, int i)
Let s be names.get(i);
Looks for s beginning from position i+1. If s is found at a position j (j > i), return j. Otherwise return -1.
public static void
removeDuplicates(ArrayList names)
Removes duplicates from ArrayList names
public static void
sort(ArrayList names)
Sorts ArrayList names
You cannot use ArrayList’s sort method.
The main method must:
1. Prompt the user for the name of the input file with a meaningful message.
2. Prompt the user for the name of the output file with a meaningful message.