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

Commit 824eee3

Browse files
committed
Lab19-20
1 parent 9ef4902 commit 824eee3

File tree

19 files changed

+414
-1
lines changed

19 files changed

+414
-1
lines changed

students/23K0565/23K0565-p01/src/main/java/ru/mirea/practice/s0000001/Pr3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ public static void main(String[] args) {
1010
int avg = s / arr.length;
1111
System.out.print("Сумма: " + s + " Среднее: " + avg);
1212
}
13-
}
13+
}
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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>23K0565</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0565-p19</artifactId>
12+
<description>19 практическая</description>
13+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package ru.mirea.practice.s0000001.n1;
2+
3+
public class InvalidInnException extends Exception {
4+
public InvalidInnException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package ru.mirea.practice.s0000001.n1;
2+
3+
import java.util.Scanner;
4+
5+
public final class Main {
6+
7+
private Main() {
8+
throw new UnsupportedOperationException("Utility class");
9+
}
10+
11+
public static void main(String[] args) {
12+
try (Scanner input = new Scanner(System.in)) {
13+
System.out.print("Введите ИНН: ");
14+
String inn = input.nextLine();
15+
16+
try {
17+
checkInn(inn);
18+
System.out.println("ИНН действителен!");
19+
} catch (InvalidInnException e) {
20+
System.out.println(e.getMessage());
21+
}
22+
}
23+
}
24+
25+
static void checkInn(String inn) throws InvalidInnException {
26+
if (inn == null || inn.length() != 12 || !inn.matches("\\d+")) {
27+
throw new InvalidInnException("Недействительный ИНН: " + inn);
28+
}
29+
}
30+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package ru.mirea.practice.s0000001.n2;
2+
3+
public class EmpString extends Exception {
4+
public EmpString(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ru.mirea.practice.s0000001.n2;
2+
3+
import java.util.List;
4+
import java.util.ArrayList;
5+
import java.util.Collections;
6+
import java.util.Comparator;
7+
8+
public class LabClass {
9+
private List<Student> students = new ArrayList<>();
10+
11+
public void addStudent(Student student) {
12+
students.add(student);
13+
}
14+
15+
public void sortStudentsByScore() {
16+
Collections.sort(students, Comparator.comparingDouble(Student::getAverageScore).reversed());
17+
}
18+
19+
public Student findStudentByFio(String fio) throws NStudent, EmpString {
20+
if (fio == null || fio.trim().isEmpty()) {
21+
throw new EmpString("ФИО не может быть пустым:(");
22+
}
23+
return students.stream()
24+
.filter(student -> student.getFio().equalsIgnoreCase(fio))
25+
.findFirst()
26+
.orElseThrow(() -> new NStudent("Студент с ФИО " + fio + " не найден"));
27+
}
28+
29+
public List<Student> getStudents() {
30+
return students;
31+
}
32+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ru.mirea.practice.s0000001.n2;
2+
3+
import java.util.Scanner;
4+
5+
public class LabClassUI {
6+
private LabClass labClass = new LabClass();
7+
private Scanner scanner = new Scanner(System.in);
8+
9+
public void addStudent() {
10+
System.out.print("Введите ФИО: ");
11+
String fio = scanner.nextLine();
12+
System.out.print("Введите средний балл: ");
13+
double averageScore = scanner.nextDouble();
14+
scanner.nextLine(); // очистка буфера
15+
labClass.addStudent(new Student(fio, averageScore));
16+
System.out.println("Студент добавлен.");
17+
}
18+
19+
public void sortStudents() {
20+
labClass.sortStudentsByScore();
21+
System.out.println("Студенты отсортированы по среднему баллу.");
22+
}
23+
24+
public void findStudent() {
25+
System.out.print("Введите ФИО для поиска: ");
26+
String fio = scanner.nextLine();
27+
try {
28+
Student student = labClass.findStudentByFio(fio);
29+
System.out.println("Найден студент: " + student.getFio() + ", Средний балл: " + student.getAverageScore());
30+
} catch (NStudent | EmpString e) {
31+
System.out.println(e.getMessage());
32+
}
33+
}
34+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package ru.mirea.practice.s0000001.n2;
2+
3+
public class NStudent extends Exception {
4+
public NStudent(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package ru.mirea.practice.s0000001.n2;
2+
3+
public class Student {
4+
private String fio;
5+
private double averageScore;
6+
7+
public Student(String fio, double averageScore) {
8+
this.fio = fio;
9+
this.averageScore = averageScore;
10+
}
11+
12+
public String getFio() {
13+
return fio;
14+
}
15+
16+
public double getAverageScore() {
17+
return averageScore;
18+
}
19+
}

0 commit comments

Comments
 (0)