File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed
Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 11import groupStudents .Group ;
22import student .Student ;
3+ import student .StudentComparatorByName ;
34
45public class Main {
56
@@ -42,7 +43,16 @@ public static void main(String[] args) {
4243 groupA .addAll (groupB );
4344
4445 /* Alphabetical sorting */
45- groupA .sort ();
46+ groupA .sort (new StudentComparatorByName ());
47+
48+ /* Sorting by best ball*/
49+ groupA .sort ((o1 , o2 ) -> {
50+ double averageScore1 = o1 .getAverageScore ();
51+ double averageScore2 = o2 .getAverageScore ();
52+ if (averageScore1 > averageScore1 ) return 1 ;
53+ else if (averageScore1 == averageScore2 ) return 0 ;
54+ else return -1 ;
55+ });
4656
4757 /* Check if group contains in other group */
4858 System .out .println ("Group " + groupB .getName () + (groupA .containsAll (groupB ) ? " is contains" : " not contains" ) + " in group " + groupA .getName ());
Original file line number Diff line number Diff line change 44import student .StudentComparatorByName ;
55
66import java .util .ArrayList ;
7+ import java .util .Comparator ;
78import java .util .function .Predicate ;
89
910public class Group extends ArrayList <Student > {
Original file line number Diff line number Diff line change @@ -21,4 +21,12 @@ public Student(String surename){
2121 this .surename = surename ;
2222 this .subjects = Subject .init ();
2323 }
24+
25+ public double getAverageScore () {
26+ double result = 0 ;
27+ for (Subject s : subjects ) {
28+ result += s .getAverageBall ();
29+ }
30+ return result / subjects .size ();
31+ }
2432}
You can’t perform that action at this time.
0 commit comments