/Users/johnr/Desktop/IA Submissions/IA Final Submission 000307-0029 - Kazuki/Product/TutoringStudent_Kazuki/src/tutoringstudent/SortAndSearch.java
  1 package tutoringstudent;
  2 
  3 /*
  4  * To change this license header, choose License Headers in Project Properties.
  5  * To change this template file, choose Tools | Templates
  6  * and open the template in the editor.
  7  */
  8 import java.util.ArrayList;
  9 import java.util.Collection;
 10 import java.util.Collections;
 11 import static java.util.Collections.list;
 12 import java.util.Comparator;
 13 
 14 /**
 15  *
 16  * @author 17104
 17  */
 18 public class SortAndSearch {
 19          
 20     // Sort by Full Name
 21     public void selectionSortOfStudentName(ArrayList<StudentClass> students) {
 22         int minIndex = 0;
 23         for (int i = 0; i < students.size() - 1; i++) {
 24                   // Assumed index of smallest remaining value.
 25             for (int j = i + 1; j < students.size(); j++) {
 26                 if (students.get(i).getfullName().compareTo(students.get(minIndex).getfullName()) < 1 ) {
 27                     minIndex = j;  // Remember index of new minimum
 28                 }
 29             }
 30             if (minIndex != i) {
 31                 //Exchange current element with smallest remaining.
 32                 //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
 33                 StudentClass temp = students.get(i);
 34                 students.set(i, students.get(minIndex));
 35                 students.set(minIndex, temp);
 36             }
 37         }
 38 
 39     }
 40     
 41     // Sort by Gender
 42     public void selectionSortOfStudentGender(ArrayList<StudentClass> students) {
 43         for (int i = 0; i < students.size() - 1; i++) {
 44             int minIndex = i;      // Assumed index of smallest remaining value.
 45             for (int j = i + 1; j < students.size(); j++) {
 46                 if (students.get(i).getgender().compareTo(students.get(minIndex).getgender()) <1) {
 47                     minIndex = j;  // Remember index of new minimum
 48                 }
 49             }
 50             if (minIndex != i) {
 51                 //Exchange current element with smallest remaining.
 52                 //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
 53                 StudentClass temp = students.get(i);
 54                 students.set(i, students.get(minIndex));
 55                 students.set(minIndex, temp);
 56             }
 57         }
 58     }
 59     
 60     // Search by Full Name
 61     public int searchByFullName(ArrayList<StudentClass> students, String input)
 62     {
 63         for ( int i = 0 ; i < students.size() ; i++)
 64         {
 65             if (students.get(i).getfullName().equalsIgnoreCase(input));
 66             {
 67                 return i;
 68             }
 69         }
 70         return -1;
 71     }
 72             
 73     // Search by Nick Name
 74     public int searchByNickName(ArrayList<StudentClass> students, String input)
 75     {
 76         for ( int i = 0 ; i < students.size() ; i++)
 77         {
 78             if (students.get(i).getnickName().equalsIgnoreCase(input));
 79             {
 80                 return i;
 81             }
 82         }
 83         return -1;
 84     }
 85            
 86     public int searchByNationality(ArrayList<StudentClass> students, String input)
 87     {
 88         for ( int i = 0 ; i < students.size() ; i++)
 89         {
 90             if (students.get(i).getnationality().equalsIgnoreCase(input));
 91             {
 92                 return i;
 93             }
 94         }
 95         return -1;
 96     }
 97     
 98     public int searchByGrade(ArrayList<StudentClass> students, String input)
 99     {
100         for ( int i = 0 ; i < students.size() ; i++)
101         {
102             if (students.get(i).getgrade().equalsIgnoreCase(input));
103             {
104                 return i;
105             }
106         }
107         return -1;
108     }
109 }
110