Lab 3 (100 pts) due Monday, January 28 at 9:20am on Canvas Pair Programming Required (Or No Credit)!
Removing Duplicate Names
Jiming Wu Leanna Perez Xing Li Stacey Cahill James Brown Mohammed Abbas Kumari Chakrabarti Shakil Smith James Brown Jung Ahrin Pedro Martinez Ally Gu Tamara White Alvin Ngo Pedro Martinez Abir Fadel Brad Feinman Xiaohang Yue
/** * Duplicates.java * @author * CIS 36B */ import java.io.*; import java.util.Scanner; public class Duplicates { public static void main(String[] args) throws IOException{ Scanner input = new Scanner(System.in); int duplicates = 0, numElements = 0; String fileName = ""; String[] roster = new String[25]; //leaving extra room at end of array System.out.print("Welcome!\n\nPlease enter the name of your file: "); System.out.println("\nI found " + numElements + " names in " + fileName + " and " + duplicates + " duplicate names."); System.out.print("\nPlease enter the name of the output file: "); System.out.println("\nThe updated roster has now been written to " + fileName + "."); System.out.println("\nGoodbye!"); } //end of main /** * Writes the contents of the array to the specified file * with each element on its own line * @param array the list of Strings * @param numElements the current number of elements in the array * @param fileName the file name to write the data into */ public static void printArray(String[] array, int numElements, String fileName) throws IOException { } /** * Reads in the contents of a file and stores it as an array * Also counts the number of elements in the file and returns * the count * @param array the list of String values * @param fileName the name of file to read from * @return the number of elements in the file */ public static int readFileArray(String[] array, String fileName) throws IOException{ return -1; } /** * Sorts an array of Strings from smallest to largest * using the insertion sort algorithm * @param array the list of String values * @param numElements the current number of elements */ public static void insertionSort(String array[], int numElements) { } /** * Detects and removes duplicate values inside an array * Calls the remove method each time it finds a duplicate * @param array the list of String values containing duplicates * @param numElements the current number of elements stored * @return the total number of duplicates found */ public static int removeDuplicates(String[] array, int numElements) { return -1; } /** * Removes an element from an array at a specified index * @param array the list of String values * @param numElements the current number of elements stored * @param indexToRemove where in the array to remove the element */ public static void remove(String array[], int numElements, int indexToRemove) { } }
Sample Output: Welcome! Please enter the name of your file: roster.txt I found 18 names in roster.txt and 2 duplicate names. Please enter the name of the output file: outfile.txt The updated roster has now been written to outfile.txt. Goodbye! Corresponding Output File: Abir Fadel Ally Gu Alvin Ngo Brad Feinman James Brown Jiming Wu Jung Ahrin Kumari Chakrabarti Leanna Perez Mohammed Abbas Pedro Martinez Shakil Smith Stacey Cahill Tamara White Xiaohang Yue Xing Li Another Example Input File: Jiming Wu Leanna Perez Xing Li Stacey Cahill James Brown Mohammed Abbas Kumari Chakrabarti Shakil Smith Tamara White Jung Ahrin Alvin Ngo Pedro Martinez Ally Gu Tamara White Kumari Chakrabarti Alvin Ngo Pedro Martinez Abir Fadel Xing Li Brad Feinman Xiaohang Yue Sample Output Welcome! Please enter the name of your file: students36B.txt I found 21 names in students36B.txt and 5 duplicate names. Please enter the name of the output file: sortedStudents.txt The updated roster has now been written to sortedStudents.txt. Goodbye! Corresponding Output File: Abir Fadel Ally Gu Alvin Ngo Brad Feinman James Brown Jiming Wu Jung Ahrin Kumari Chakrabarti Leanna Perez Mohammed Abbas Pedro Martinez Shakil Smith Stacey Cahill Tamara White Xiaohang Yue Xing Li |