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!
}
//Java program
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 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
Student [] temp= new Student [10];
mergesort(myStudents , temp ,0 , 9);
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!");
}
}
public static void merge(Student a[],Student temp[],int l,int m,int
r){
int temp_pos=l,size=r-l+1,left_end=m-1;
while(l<=left_end&&m<=r){
if(a[l].getName().compareTo(a[m].getName())<0)temp[temp_pos++]=a[l++];
else temp[temp_pos++]=a[m++];
}
while(l<=left_end)temp[temp_pos++]=a[l++];
while(m<=r)temp[temp_pos++]=a[m++];
for(int i=0;i<size;i++){
a[r]=temp[r];
r--;
}
}
public static void mergesort(Student a[],Student temp[],int l,int
r){
if(l<r){
int mid=l+(r-l)/2;
mergesort(a,temp,l,mid);
mergesort(a,temp,mid+1,r);
merge(a,temp,l,mid+1,r);
}
}
}
//sample output
![<terminated> Main (2) [Java Application] C: Program Files\Java\jdk1.8.0 151 bin javaw.exe Sort Test Passed!](http://img.homeworklib.com/questions/c9e921d0-9bbd-11ea-af7e-b9ebf7c5ef3d.png?x-oss-process=image/resize,w_560)
PLEASE READ ALL Modify the MergeSort code provided in class (if you find a mistake with...
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...
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)...
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...
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...