Source of SortStudents.java


  1: import java.util.Scanner;
  2: import java.util.Arrays;

  4: public class SortStudents {

  6:     public static void main(String[] args) {
  7:         // create list of Students
  8:         Student jake = new Student("Jake");
  9:         Student angie = new Student("Angie");
 10:         Student geety = new Student("Geety");
 11:         Student[] ss = new Student[]{jake, angie, geety};

 13:         // add grades to students and students to list
 14:         jake.setAsgnGrades(new int[]{75, 65});
 15:         angie.setAsgnGrades(new int[]{55, 65});
 16:         geety.setAsgnGrades(new int[]{95, 85});
 17:         Student.releaseAssignment(2);

 19:         // report original
 20:         System.out.println("\nHere is a list of Students:");
 21:         for (int i = 0; i < ss.length; ++i) {
 22:             ss[i].printStudentRecord();
 23:         }
 24:         pause();

 26:         // sort and present sorted
 27:         Arrays.sort(ss, Student.BY_NAME);
 28:         System.out.println("\nHere is that same list, sorted by name:");
 29:         for (int i = 0; i < ss.length; ++i) {
 30:             ss[i].printStudentRecord();
 31:         }
 32:         pause();

 34:         // sort and present sorted
 35:         Arrays.sort(ss, Student.BY_GRADE);
 36:         System.out.println("\nHere is that same list, sorted by grade:");
 37:         for (int i = 0; i < ss.length; ++i) {
 38:             ss[i].printStudentRecord();
 39:         }
 40:         pause();

 42:         // sort and present sorted
 43:         Arrays.sort(ss, Student.BY_ANUMBER);
 44:         System.out.println("\nHere is that same list, sorted by A-#:");
 45:         for (int i = 0; i < ss.length; ++i) {
 46:             ss[i].printStudentRecord();
 47:         }
 48:         pause();
 49:     }

 51:     private static void pause() {
 52:         Scanner kbd = new Scanner(System.in);
 53:         System.out.print("\nPress enter...");
 54:         kbd.nextLine();
 55:         System.out.println();
 56:     }

 58: }