MERGESORT ASSIGNMENT FOLLOW THE FORMAT
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
HERE IS THE 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);
}
}
AND HERE IS THE GIVEN MAIN CLASS WE MUST USE
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!
}
import java.util.Arrays;
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);
}
}
public class Main {
public static Student[] merge(Student[] firstSplit, Student[] secondSplit) {
Student[] toReturn = new Student[firstSplit.length + secondSplit.length];
int firstIter = 0;
int secondIter = 0;
int index = 0;
while (firstIter < firstSplit.length && secondIter < secondSplit.length) {
if (firstSplit[firstIter].getName().compareTo(secondSplit[secondIter].getName()) < 0) {
toReturn[index] = firstSplit[firstIter];
firstIter++;
index++;
} else {
toReturn[index] = secondSplit[secondIter];
secondIter++;
index++;
}
}
while (firstIter < firstSplit.length) {
toReturn[index] = firstSplit[firstIter];
firstIter++;
index++;
}
while (secondIter < secondSplit.length) {
toReturn[index] = secondSplit[secondIter];
secondIter++;
index++;
}
return toReturn;
}
public static Student[] mergeSort(Student[] arrayToSort) {
if (arrayToSort.length == 1) {
return arrayToSort;
}
Student split1[];
Student split2[];
// find midepoint
split1 = Arrays.copyOfRange(arrayToSort, 0, arrayToSort.length / 2);
split2 = Arrays.copyOfRange(arrayToSort, arrayToSort.length / 2, arrayToSort.length);
split1 = mergeSort(split1);
split2 = mergeSort(split2);
arrayToSort = merge(split1, split2);
return arrayToSort;
}
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);
myStudents = mergeSort(myStudents);
// 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!");
}
}
}

Please upvote, as i have given the exact answer as asked in
question. Still in case of any concerns in code, let me know in
comments. Thanks!
MERGESORT ASSIGNMENT FOLLOW THE FORMAT Modify the MergeSort code provided in class (if you find a...
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)...
java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and short by name, course, instructor, and location. ///main public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Student>students = new ArrayList<>(); int choice; while(true) { displayMenu(); choice = in.nextInt(); switch(choice) { case 1: in.nextLine(); System.out.println("Enter Student Name"); String name...
For the code below write a public static main() method in class Student that: - creates an ArrayList<Student> object called students - adds 4 new Student objects to the students list, with some made up names and dates - sort the students list by name and display the sorted collection to System.out. use function getCompByName() - sort the students list by enrollment date and display the sorted collection to System.out. use function getCompByDate() import java.util.Comparator; import java.util.Date; public...
I need code in java
The Student class:
CODE IN JAVA:
Student.java file:
public class Student {
private String name;
private double gpa;
private int idNumber;
public Student() {
this.name = "";
this.gpa = 0;
this.idNumber = 0;
}
public Student(String name, double gpa, int
idNumber) {
this.name = name;
this.gpa = gpa;
this.idNumber = idNumber;
}
public Student(Student s)...
Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...
Java help: 1.1) Create a class TA that extends class Student. 1.2) Add a variable to the TA class to represent the course the student is TA'ing. 1.3) Provide a constructor for the class so the code in the PeopleFactory will work as provided. 1.4) Provide a toString() method for the TA class so that TA's will output as shown in the sample code. Provide a class Staff so that you can un-comment the lines of code in the PeopleFactory class that...
A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...
A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...
JAVA program Note: you can't change anything is already written Student.java public class Student { private String name; private String major; private double gpa; public Student(String name, String major, double gpa) { // TO-DO: Assign the given parameters to the data fields. Use the this keyword. } public double getGPA() { // TO-DO: return this.gpa } public String getName() { // TO-DO: return this.name }...
import java.util.Scanner; public class StudentClient { public static void main(String[] args) { Student s1 = new Student(); Student s2 = new Student("Smith", "123-45-6789", 3.2); Student s3 = new Student("Jones", "987-65-4321", 3.7); System.out.println("The name of student #1 is "); System.out.println("The social security number of student #1 is " + s1.toString()); System.out.println("Student #2 is " + s2); System.out.println("the name of student #3 is " + s3.getName()); System.out.println("The social security number...