Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit 1cdff3d

Browse files
committed
Лабораторная 10
1 parent 7b182ef commit 1cdff3d

File tree

6 files changed

+132
-0
lines changed

6 files changed

+132
-0
lines changed

students/23K0140/23K0140-p10/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0140</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0140-p10</artifactId>
12+
<description>Лабораторная 10</description>
13+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package ru.mirea.practice.s23k0140.tasks;
2+
3+
public abstract class Main {
4+
public static void main(String[] args) {
5+
SortingStudentByGpa sort = new SortingStudentByGpa();
6+
7+
sort.setArray();
8+
9+
System.out.println("Before: ");
10+
sort.outArray();
11+
12+
sort.quickSort();
13+
System.out.println("\nSorting by GPA: ");
14+
sort.outArray();
15+
16+
sort.sortByLastName();
17+
System.out.println("\nSorting by Last name: ");
18+
sort.outArray();
19+
20+
}
21+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ru.mirea.practice.s23k0140.tasks;
2+
3+
import java.util.ArrayList;
4+
import java.util.Comparator;
5+
import java.util.List;
6+
7+
public abstract class SortingByMerge {
8+
public static List<Student> mergeSort(List<Student> list1, List<Student> list2) {
9+
10+
List<Student> mergedList = new ArrayList<>(list1);
11+
mergedList.addAll(list2);
12+
13+
mergedList.sort(Comparator.comparingDouble(Student::getGpa).reversed());
14+
return mergedList;
15+
}
16+
17+
public static void main(String[] args) {
18+
19+
List<Student> list1 = new ArrayList<>();
20+
list1.add(new Student("Aleksandr", "Pushkin", "Computer Science", 2, "KVBO-01", 4.8));
21+
list1.add(new Student("Lev", "Tolstoy", "Artificial Intelegence", 1, "KABO-03", 3.1));
22+
23+
List<Student> list2 = new ArrayList<>();
24+
list2.add(new Student("Sergey", "Esenin", "Programming", 2, "KBB0-04", 2.9));
25+
list2.add(new Student("Ivan", "Turgenev", "Physics", 4, "KKCO-02", 5.0));
26+
27+
List<Student> mergedList = mergeSort(list1, list2);
28+
29+
System.out.println("Merged and sorted student list:");
30+
for (Student student : mergedList) {
31+
System.out.println(student);
32+
}
33+
}
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package ru.mirea.practice.s23k0140.tasks;
2+
3+
import java.util.ArrayList;
4+
import java.util.Comparator;
5+
import java.util.List;
6+
7+
public class SortingStudentByGpa {
8+
9+
private final List<Student> students;
10+
11+
public SortingStudentByGpa() {
12+
this.students = new ArrayList<>();
13+
}
14+
15+
public void setArray() {
16+
students.add(new Student("Aleksandr", "Pushkin", "Computer Science", 2, "KVBO-01", 4.8));
17+
students.add(new Student("Lev", "Tolstoy", "Artificial Intelegence", 1, "KABO-03", 3.1));
18+
students.add(new Student("Sergey", "Esenin", "Programming", 2, "KBB0-04", 2.9));
19+
students.add(new Student("Ivan", "Turgenev", "Physics", 4, "KKCO-02", 5.0));
20+
}
21+
22+
public void outArray() {
23+
for (Student student : students) {
24+
System.out.println(student);
25+
}
26+
}
27+
28+
public void quickSort() {
29+
students.sort(Comparator.comparingDouble(Student::getGpa).reversed());
30+
}
31+
32+
public void sortByLastName() {
33+
students.sort(Comparator.comparing(Student::toString));
34+
}
35+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package ru.mirea.practice.s23k0140.tasks;
2+
3+
public class Student {
4+
private final String firstName;
5+
private final String lastName;
6+
private final String speciality;
7+
private final int course;
8+
private final String group;
9+
private final double gpa;
10+
11+
public Student(String firstName, String lastName, String speciality, int course, String group, double gpa) {
12+
this.firstName = firstName;
13+
this.lastName = lastName;
14+
this.speciality = speciality;
15+
this.course = course;
16+
this.group = group;
17+
this.gpa = gpa;
18+
}
19+
20+
public double getGpa() {
21+
return gpa;
22+
}
23+
24+
public String toString() {
25+
return "Student{FirstName: " + firstName + ", LastName: " + lastName + ", Speciality: "
26+
+ speciality + ", Course: " + course + ", Group: " + group + ", gpa: " + gpa + "}";
27+
}
28+
}

students/23K0140/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
<module>23K0140-p07</module>
2424
<module>23K0140-p08</module>
2525
<module>23K0140-p09</module>
26+
<module>23K0140-p10</module>
2627
</modules>
2728
</project>

0 commit comments

Comments
 (0)