Search code examples
javaarraylistiowriterreader

Reading and writing a text file in ascending order. ( Small/annoying error- nearly completed)


    Collections.sort(orderedStudents, new Comparator<Student>() {
        public int compare(Student s1, Student s2) {
            return s2.getAggregate().compareTo(s1.getAggregate());
        }
    });

This is the method i used.


Solution

  • The problem is the getAggregate method:

    public Double getAggregate(){
        double d = 0;
        double aggregatescore = d/marks.size();
        return aggregatescore;
    }
    

    Since d is set to be zero, this method will return always 0, so the Collections.sort(...) method will do nothing