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

Please help me write this code in Java 8 . I already have some of it done, but I

ID: 3744594 • Letter: P

Question

Please help me write this code in Java 8. I already have some of it done, but I need help with writing the code for sorting using merge, quick, and heap sort. What I have now for quick sort gives me a wrong output, can you please make sure that the solution you provide gets the correct sample outputs after inputting the sample input given in the question for each of the three sorting methods. This is what I have done so far: pastebin [dot] com/qx5d66G0

Please make sure that the code meets all the needed requirements mentioned in the question under each part such as in INPUT FORMAT, OUTPUT FORMAT, AND CONSTRAINTS. Please include screenshots of your input and output, which should match the ones in the question. Thank You!

You'll be given a list of students, and you'll need to sort it using merge sort, heap sort, and quick sort. We want to sort the students according to graduation year (soonest first), and for students with the same graduation year, alphabetically by first name (and if there are any students with the same first name and graduation year, ties should be broken by last name). However, rather than just printing the final sorted list: for merge sort you'lI print the partially sorted list after each call to merge, for quick sort you'll print the partially sorted list after each call to partition, and for heap sort you'l print the list after it has been converted to a heap and the partially sorted list after each call to extractMax. You will have 3 files named: MergeSort.java, HeapSort.java, and QuickSort.java. Constraints You can assume n is a non-negative integer. You can further assume the list contains no students with the same first name, last name, and graduation year. For merge sort when splitting your array, if it has odd size, make the left half larger than the right half. For quick sort when choosing your pivot, if the array has even size, choose the left of the two middle elements Input Format The first line of the input consists of an integer, n, indicating the number of words you'll need to sort. The next n lines will each consist of student data with space separated first name, last name, and graduation year, in that order. The input will terminate with a blank line Output Format You will be printing the partially sorted list: for merge sort as many times as merge is called (the last time will be entirely sorted), for quick sort you will be printing the partially sorted list as many times as partition is called (the last time will be entirely sorted), and for heap sort you will be printing the partially sorted list after it has been heapified and again after every call to extractMax (the last time will be entirely sorted). Each student should appear on a new line without terminating whitespace, space separated in the same format it was provided in the input, and each partially sorted list should be followed by a blank line to indicate where it ends and the next one begins

Explanation / Answer

I have implemented the merge sort array technique. you can use it in your program

MergeSortArray.java
import java.util.Scanner;

//Driver class
public class MergeSortArray {
static String ar1[][],ar[][];
public static void main(String args[]){
int noOfElement;
MergeSortArray as=new MergeSortArray();
//Creating object of scanner to take input from the user
Scanner inp=new Scanner(System.in);
System.out.print("Enter the number of records= ");
noOfElement=inp.nextInt();
int row=noOfElement;
int col=3;
ar1=new String[row][col];
ar=new String[row][col];
for(int i=0;i<row;i++){
System.out.print("Enter the "+(i+1)+" record=");
ar[i][0]=inp.next();
ar[i][1]=inp.next();
ar[i][2]=inp.next();
}
System.out.println(noOfElement);
as.sorting(0,row-1);
for(int a=0;a<ar.length;a++){
System.out.println(ar[a][0]+" "+ar[a][1]+" "+ar[a][2]);
}
}
//function to sort array using merge sort
public void sorting(int low,int high){//lower index and higher index as argument to the function
if(low<high){//calculating if low>high then the array will be sorted else sort the array
int mid=low+(high-low)/2;//calculate mid index to break the array into two halves
sorting(low,mid);//calling sorting function to sort the left subarray
sorting(mid+1,high);//calling sorting function to sort the right subarray
merge(low,mid,high);//calling function to merge two subarrays
}
}
public void merge(int low,int m, int high){//merging function
for(int i=0;i<=high;i++){//copying the value of the array in a temporary array ar1
ar1[i][0]=ar[i][0];
ar1[i][1]=ar[i][1];
ar1[i][2]=ar[i][2];
}
int i=low,j=m+1,k=low;//initializing variable
while(i<=m && j<=high){//checking if the value of i is less than mid index and value of j is less than higher index
if(Integer.parseInt(ar1[i][2])<=Integer.parseInt(ar1[j][2])){//swap the values
ar[k][0]=ar1[i][0];//put the sorted value in the original array
ar[k][1]=ar1[i][1];//put the sorted value in the original array
ar[k][2]=ar1[i][2];//put the sorted value in the original array
i++;//increment loop variable
}
else{
ar[k][0]=ar1[j][0];//copy content of temporary variable to original array
ar[k][1]=ar1[j][1];
ar[k][2]=ar1[j][2];   
j++;//increment loop4 variable
}
k++;
}
while(i<=m){//if value of i is less than the mid index then copy value of temporary array to the original array
ar[k][0]=ar1[i][0];//copy content of temporary variable to original array
ar[k][1]=ar1[i][1];
ar[k][2]=ar1[i][2];   
k++;//increment loop variable
i++;
}
for(int a=0;a<ar.length;a++){
System.out.println(ar[a][0]+" "+ar[a][1]+" "+ar[a][2]);
}
}
}

Output:

run:
Enter the number of records= 8
Enter the 1 record=deniaell rothermail 2015
Enter the 2 record=sarah satan-pardo 2017
Enter the 3 record=david satan-pardo 2015
Enter the 4 record=alisa anguen 2015
Enter the 5 record=todd hirch 2017
Enter the 6 record=lina kroehlin 2015
Enter the 7 record=jesse gieger 2014
Enter the 8 record=anita garcia 2017

8

deniaell rothermail 2015
sarah satan-pardo 2017
david satan-pardo 2015
alisa anguen 2015
todd hirch 2017
lina kroehlin 2015
jesse gieger 2014
anita garcia 2017

deniaell rothermail 2015
sarah satan-pardo 2017
david satan-pardo 2015
alisa anguen 2015
todd hirch 2017
lina kroehlin 2015
jesse gieger 2014
anita garcia 2017

deniaell rothermail 2015
david satan-pardo 2015
alisa anguen 2015
sarah satan-pardo 2017
todd hirch 2017
lina kroehlin 2015
jesse gieger 2014
anita garcia 2017

deniaell rothermail 2015
david satan-pardo 2015
alisa anguen 2015
sarah satan-pardo 2017
lina kroehlin 2015
todd hirch 2017
jesse gieger 2014
anita garcia 2017

deniaell rothermail 2015
david satan-pardo 2015
alisa anguen 2015
sarah satan-pardo 2017
lina kroehlin 2015
todd hirch 2017
jesse gieger 2014
anita garcia 2017

deniaell rothermail 2015
david satan-pardo 2015
alisa anguen 2015
sarah satan-pardo 2017
jesse gieger 2014
lina kroehlin 2015
todd hirch 2017
anita garcia 2017

jesse gieger 2014
deniaell rothermail 2015
david satan-pardo 2015
alisa anguen 2015
lina kroehlin 2015
sarah satan-pardo 2017
todd hirch 2017
anita garcia 2017

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