Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```
- public void ordenarNomeCurso() {
- try {
- SortedByName objectName = new SortedByName(path); // create a sorting object that sorts by name
- SortedByCourse objectCourse = new SortedByCourse(path); // create a sorting object that sorts by course
- ArrayList<Student> data = objectCourse.listStudent(); // create a list to get the list sorted by course
- ArrayList<String> courses = new ArrayList<String>(); // list to store all courses inside the full list of students
- ArrayList<Student> dataPerCourse = new ArrayList<Student>(); // list to store the students per course
- ArrayList<Student> finalData = new ArrayList<Student>(); // final list to have the now sorted by name and by course students
- courses.add(data.get(0).getCourse()); // add the first course so it can get used for comparison
- for (Student data1 : data) { // for each to fill the courses list
- int aux = 0;
- for (int i = 0; i < courses.size(); i++) {
- if (data1.getCourse().equals(courses.get(i))) {
- aux++;
- }
- }
- if (aux == 0) {
- courses.add(data1.getCourse());
- }
- }
- for (int i = 0; i < courses.size(); i++) { // goes through each course
- for (Student data2 : data) {
- if (data2.getCourse().equals(courses.get(i))) {
- dataPerCourse.add(data2); // gets all the students that are within that course
- }
- }
- objectName.setArray(dataPerCourse); // sets the objectName's list as the list of one course to be sorted by name
- finalData.addAll((objectName.listStudent())); // adds the list of already sorted students
- dataPerCourse.removeAll(dataPerCourse); // removes the students from this course
- }
- printOnGrid(finalData); // prints on the grid the full list
- } catch (Exception e) {
- JOptionPane.showMessageDialog(rootPane, e);
- }
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement