SHARE
TWEET

Untitled

a guest Feb 26th, 2020 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ```
  2. public void ordenarNomeCurso() {
  3.         try {
  4.             SortedByName objectName = new SortedByName(path); // create a sorting object that sorts by name
  5.             SortedByCourse objectCourse = new SortedByCourse(path); // create a sorting object that sorts by course
  6.             ArrayList<Student> data = objectCourse.listStudent(); // create a list to get the list sorted by course
  7.             ArrayList<String> courses = new ArrayList<String>(); // list to store all courses inside the full list of students
  8.             ArrayList<Student> dataPerCourse = new ArrayList<Student>(); // list to store the students per course
  9.             ArrayList<Student> finalData = new ArrayList<Student>(); // final list to have the now sorted by name and by course students
  10.  
  11.             courses.add(data.get(0).getCourse()); // add the first course so it can get used for comparison
  12.  
  13.             for (Student data1 : data) { // for each to fill the courses list
  14.                 int aux = 0;
  15.                 for (int i = 0; i < courses.size(); i++) {
  16.                     if (data1.getCourse().equals(courses.get(i))) {
  17.                         aux++;
  18.                     }
  19.                 }
  20.                 if (aux == 0) {
  21.                     courses.add(data1.getCourse());
  22.                 }
  23.             }
  24.  
  25.             for (int i = 0; i < courses.size(); i++) { // goes through each course
  26.                 for (Student data2 : data) {
  27.                     if (data2.getCourse().equals(courses.get(i))) {
  28.                         dataPerCourse.add(data2); // gets all the students that are within that course
  29.                     }
  30.                 }
  31.                
  32.                 objectName.setArray(dataPerCourse); // sets the objectName's list as the list of one course to be sorted by name
  33.                 finalData.addAll((objectName.listStudent())); // adds the list of already sorted students
  34.                 dataPerCourse.removeAll(dataPerCourse); // removes the students from this course
  35.             }
  36.  
  37.             printOnGrid(finalData); // prints on the grid the full list
  38.  
  39.         } catch (Exception e) {
  40.             JOptionPane.showMessageDialog(rootPane, e);
  41.         }
  42.     }
  43. ```
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top