101 lines
3.4 KiB
Java
101 lines
3.4 KiB
Java
/*
|
|
* %W% %E% Dymik739
|
|
* Email: dymik739@109.86.70.81
|
|
*
|
|
* Copyright (C) 2023 FIOT Dev Team
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
import java.util.Arrays;
|
|
|
|
/**
|
|
* Group class defines a representation of a university group with students
|
|
* that can be used as a convenient structure to look at students' statistics.
|
|
*
|
|
* @version 0.1 20 May 2023
|
|
* @author Dymik739
|
|
*/
|
|
public class Group {
|
|
/**
|
|
* Main method which should be executed at the start of this application.
|
|
*
|
|
* @since 0.1
|
|
*/
|
|
public static void main() {
|
|
Student[] studentList = {
|
|
// name, results, motivation%, ability%, course№
|
|
new Student("Davie", 16.3, 93.5, 98.9, 5),
|
|
new Student("Terry", 99.4, 49.3, 73.2, 7),
|
|
new Student("Mark", 67.9, 15.5, 7.8, 4),
|
|
new Student("Rand", 85.5, 82.6, 99.9, 12),
|
|
new Student("Steve", 1.2, 99.8, 99.2, 1)
|
|
};
|
|
|
|
System.out.println("Original students array:");
|
|
printStudents(studentList);
|
|
|
|
Arrays.sort(studentList, (o1, o2) -> o1.getName().compareTo(o2.getName()));
|
|
|
|
System.out.println("\nArray, sorted by students' name:");
|
|
printStudents(studentList);
|
|
|
|
Arrays.sort(studentList, (o1, o2) ->
|
|
compareDouble(o2.getResults(), o1.getResults()));
|
|
|
|
System.out.println("\nArray, sorted by the reverse of students' " +
|
|
"score results:");
|
|
printStudents(studentList);
|
|
|
|
System.out.println("\nAs we can clearly see, " +
|
|
studentList[studentList.length-1].getName() + " with " +
|
|
studentList[studentList.length-1].getMotivationPercent() +
|
|
"% of motivation and " +
|
|
studentList[studentList.length-1].getLearningAbilitiesPercent() +
|
|
"% ability to learn will be the one who is kicked " +
|
|
"from this university, because such is our life.");
|
|
}
|
|
|
|
/**
|
|
* Outputs to stdout a given array of students in a fancy way.
|
|
*
|
|
* @param array array to print out
|
|
*/
|
|
private static void printStudents(Student[] array) {
|
|
for (Student s : array) {
|
|
System.out.println(s);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Compares numbers of type Double
|
|
*
|
|
* @param i1 first number to compare
|
|
* @param i2 second number to compare
|
|
* @return if the first argument is greater, 1 is returned
|
|
* if the second argument is greater, -1 is returned
|
|
* if the arguments are equal, 0 is returned
|
|
*/
|
|
private static int compareDouble(double i1, double i2) {
|
|
if (i1 > i2) {
|
|
return 1;
|
|
} else if (i1 < i2) {
|
|
return -1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
}
|