Code programming

computer science

Description

public class Changing_sort_keys {
public static void main(String[] args) {
Student[] Studenteven = { new Student("smith", "fred", 95), new Student("bauer", "jack", 123),
new Student("jacobs", "carrie", 195), new Student("renquist", "abe", 148),
new Student("3ackson", "trevor", 108), new Student("perry", "fred", 225),
new Student("loceff", "fred", 44), new Student("stollings", "pamela", 452),
new Student("charters", "rodney", 295), new Student("cassar", "john", 321), };
Student[] Studentodd = { new Student("smith", "fred", 95), new Student("bauer", "jack", 123),
new Student("jacobs", "carrie", 195), new Student("renquist", "abe", 148),
new Student("3ackson", "trevor", 108), new Student("perry", "fred", 225),
new Student("loceff", "fred", 44), new Student("stollings", "pamela", 452),
new Student("charters", "rodney", 295), new Student("cassar", "john", 321),
new Student("oddman", "out", 100), };
Student[] minimumstudent = { new Student("smith", "fred", 95) };
Student[] noClass = {};
System.out.println(StudentArrayUtilities.toString("Before: ", Studenteven));
System.out.println("Sorting by default");
System.out.println("==========================");
StudentArrayUtilities.arraySort(Studenteven);
System.out.println(StudentArrayUtilities.toString("After: ", Studenteven));
System.out.println("Sorting by first name");
System.out.println("==========================");
Student.setSortKey(Student.SORT_BY_FIRST);
StudentArrayUtilities.arraySort(Studenteven);
System.out.println(StudentArrayUtilities.toString("After: ", Studenteven));
System.out.println("Sorting by total points ");
System.out.println("========================");
Student.setSortKey(Student.SORT_BY_POINTS);
StudentArrayUtilities.arraySort(Studenteven);
System.out.println(StudentArrayUtilities.toString("After: ", Studenteven));
Student.setSortKey(Student.SORT_BY_LAST);
System.out.println("Median of Studenteven= " + StudentArrayUtilities.getMedianDestructive(Studenteven));
if (Student.getSortKey() == Student.SORT_BY_LAST)
System.out.println("Successfully preserved sort key.");
else
System.out.println("ERROR.");
System.out.println("Median of Student odd= " + StudentArrayUtilities.getMedianDestructive(Studentodd));
System.out.println("Median of minimumstudent = " + StudentArrayUtilities.getMedianDestructive(minimumstudent));
System.out.println("Median of noClass = " + StudentArrayUtilities.getMedianDestructive(noClass));
}
}
class Student {
private String lastName;
private String firstName;
private int totalPoints;
public static final String DEFAULT_NAME = "zz-error";
public static final int DEFAULT_POINTS = 0;
public static final int MAX_POINTS = 1000;
public Student(String last, String first, int points) {
if (!setLastName(last))
lastName = DEFAULT_NAME;
if (!setFirstName(first))
firstName = DEFAULT_NAME;
if (!setPoints(points))
totalPoints = DEFAULT_POINTS;
}
public String getLastName() {
return lastName;
}
public String getFirstName() {
return firstName;
}
public int getTotalPoints() {
return totalPoints;
}
public boolean setLastName(String last) {
if (!validString(last))
return false;
lastName = last;
return true;
}


Related Questions in computer science category