Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement Mergesort Problem Your Mergesort implementation should be able to take

ID: 640394 • Letter: I

Question

Implement Mergesort Problem

Your Mergesort implementation should be able to take array of objects that implement the Comparable interface and sort them.

The input will be a text file containing multiple lines of the following format: . As an input argument, we will provide, which element to use for sorting. Your Comparable interface implementation and Mergesort implementation should be able to handle that input sort accordingly.

Example input file (input.txt):

Jacob Zack, 12/20/1945, MI, 76545

Chris Mathews, 1/5/1957, KT, 75878

Issac Ezk, 2/7/1998, WA, 74547

If we now run your code in the command prompt as follows: > java YourMergesort "C://input.txt" 1

We are basically asking you to sort using the first filed, that is the 'Name':

Example output:

Chris Mathews, 1/5/1957, KT, 75878

Issac Ezk, 2/7/1998, WA, 74547

Jacob Zack, 12/20/1945, MI, 76545

Again, if we run your code as :  > java YourMergesort "C://input.txt" 4 - we are basically asking you to sort using the Zip and the output would be:

Issac Ezk, 2/7/1998, WA, 74547

Chris Mathews, 1/5/1957, KT, 75878

Jacob Zack, 12/20/1945, MI, 76545

Guideline/Hint:

implement a class called 'Person' that has five instance variables: Name, DOB (you could split it into date, month and year), State, ZIP and SortCriteria.

The 'SortCriteria' could be an integer that holds the value (1 - 4) depending on the input.

Your Person class needs to implement the Compare interface.

It needs to implement the 'compareTo' mehtod. The 'compareTo' method will, depending on the 'SortCriteria', return -1, 0 or 1.

Your Megresort implementation can be just the textbook implementation that takes an array of Comparable objects.

Your 'Person' class also has to implement the 'toString' method, so that it can print out the name, dob, state and Zip at the console.

There should be a separate class that will be our starting point. It should be named as Your_Mergesort. his class will be responsible for parsing the input text file, creating the array of Person Objects and calling your Mergesort code and finally printing the array in the console.

Your_Mergesort class Code:

Explanation / Answer

import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Iterator; public class MergeSort { public static int[] mergeSort(int [] list) { if (list.length
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote