/Users/johnr/Desktop/IA_14_-_Stage_P_Upload_all_2021-04-08/CSIA_TeacherOrganizer_19927 Marazal March 25th/src/SortAndSearchStudent.java
 1 
 2 import java.util.ArrayList;
 3 
 4 /*
 5  * To change this license header, choose License Headers in Project Properties.
 6  * To change this template file, choose Tools | Templates
 7  * and open the template in the editor.
 8  */
 9 
10 /**
11  *
12  * @author 19927
13  */
14 public class SortAndSearchStudent {
15     
16 
17     public void selectionSortofStudentAttendace(ArrayList<Student> students) {
18         for (int i = 0; i < students.size() - 1; i++) {
19             int minIndex = i;      // Assumed index of smallest remaining value.
20             for (int j = i + 1; j < students.size(); j++) {
21                 if (students.get(j).getname().compareTo(students.get(minIndex).getname()) < 1 ){
22                     minIndex = j;  // Remember index of new minimum
23                 }
24             }
25             if (minIndex != i) {
26                 //Exchange current element with smallest remaining.     
27                 //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
28                 Student temp = students.get(i);
29                 students.set(i, students.get(minIndex)); 
30                 students.set(minIndex, temp);
31             }
32         }
33     } 
34     
35     public void selectionSortofClasses(ArrayList<Grade> classes) {
36         for (int i = 0; i < classes.size() - 1; i++) {
37             int minIndex = i;      // Assumed index of smallest remaining value.
38             for (int j = i + 1; j < classes.size(); j++) {
39                 if (classes.get(j).gettopicName().compareTo(classes.get(minIndex).gettopicName()) < 1 ){
40                     minIndex = j;  // Remember index of new minimum
41                 }
42             }
43             if (minIndex != i) {
44                 //Exchange current element with smallest remaining.     
45                 //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
46                 Grade temp = classes.get(i);
47                 classes.set(i, classes.get(minIndex)); 
48                 classes.set(minIndex, temp);
49             }
50         }
51     }
52     
53     public void selectionSortofClassesTestGrade(ArrayList<Grade> classes) {
54         for (int i = 0; i < classes.size() - 1; i++) {
55             int minIndex = i;      // Assumed index of smallest remaining value.
56             for (int j = i + 1; j < classes.size(); j++) {
57                 if (classes.get(j).gettopicTestGrade() < (classes.get(minIndex).gettopicTestGrade())){
58                     minIndex = j;  // Remember index of new minimum
59                 }
60             }
61             if (minIndex != i) {
62                 //Exchange current element with smallest remaining.     
63                 //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
64                 Grade temp = classes.get(i);
65                 classes.set(i, classes.get(minIndex)); 
66                 classes.set(minIndex, temp);
67             }
68         }
69     }
70     
71     
72     public int searchByName(ArrayList<Student> students, String key){
73         for(int i = 0; i < students.size(); i++){
74             if(students.get(i).getname().equalsIgnoreCase(key)){
75                 return i;
76             }
77         } 
78         return -1;
79     }
80     
81     
82 
83 }
84