Question
PLEASE READ ALL Modify the MergeSort code provided in class (if you find a mistake with it extra credit) (https://repl.it/@ashokbasawapatna/MergeSortExample) to work with Students (No
PLEASE READ ALL
Modify the MergeSort code provided in class (if you find a mistake with it extra credit)
(https://repl.it/@ashokbasawapatna/MergeSortExample) to work with Students (No need for generic types, you will only write Main.java). Then use the compareTo method for strings in Java to sort the students in Alphabetical order via MergeSort.
1) Create an array of 10 students by hand. Make sure it's not in alphabetical order. ONLY USE LOWER CASES FOR NAMES (I'll only test with that).
2) Modify the MergeSort and Merge function prototypes to work with students
3) Inside the Merge function use compareTo to determine which one comes sooner in the alphabet.
If I have two strings a and b
String a="aba";
String b="abb";
String c="aba";
System.out.println(a.compareTo(b));
System.out.println(b.compareTo(a));
System.out.println(c.compareTo(a));
Will output
-1 1 0
Note anything less than zero means the calling object is before the passed object in the dictionary
Zero means they are equal
1 means the calling object is after the passed object in the dictionary
(GIVEN STUDENT CLASS)
public final class Student { private int schoolID; private String name;
public Student(String namePassed,int schoolIDPassed) { schoolID= schoolIDPassed; name= namePassed; }
public int getSchoolID() { return schoolID; }
public void setSchoolID(int schoolIDPassed) { schoolID=schoolIDPassed; }
public String getName() { return name; }
public void setName(String namePassed) { name=namePassed; }
public boolean equals(Object toCompare) { Student temp= (Student) toCompare; return(temp.getSchoolID()==schoolID); } public String toString() { String toReturn="name: "+name+" id: "+schoolID; return (toReturn); }
}
HERE IS GIVEN MAIN CLASS
import java.util.Arrays; class Main { public static void main(String[] args) { Student [] myStudents= new Student [10]; myStudents[0]=new Student("shenice",100); myStudents[1]=new Student("bonnie", 200); myStudents[2]=new Student("johnny",300); myStudents[3]=new Student("olivia",400); myStudents[4]=new Student("ashtrash",500); myStudents[5]=new Student("jeter",600); myStudents[6]=new Student("danielle",700); myStudents[7]=new Student("rodrick",800); myStudents[8]=new Student("jeter",900); myStudents[9]=new Student("zoey",1000); //INSERT YOUR CODE TO SORT HERE AND INSERT YOUR FUNCTIONS BELOW MAIN. DO NOT DELETE THE STUFF UNDER HERE!! i.e. call your function here to sort if(myStudents[0].getName().equals("ashtrash")&&myStudents[1].getName().equals("bonnie")&&myStudents[2].getName().equals("danielle")&&myStudents[3].getName().equals("jeter")&&myStudents[4].getName().equals("jeter") && myStudents[5].getName().equals("johnny") && myStudents[6].getName().equals("olivia") &&myStudents[7].getName().equals("rodrick") && myStudents[8].getName().equals("shenice") &&myStudents[9].getName().equals("zoey")) { System.out.println("Sort Test Passed!"); } else { System.out.println("Sort test failed! Check your code!"); } } //paste your functions down here! }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started