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

Commit a73a17f

Browse files
committed
Лабораторная 21-32
1 parent 4749714 commit a73a17f

File tree

71 files changed

+1766
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1766
-0
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<module>students/23K0186</module>
8282
<module>students/23K0755</module>
8383
<module>students/23K1292</module>
84+
<module>students/23K0687</module>
8485
</modules>
8586
<dependencies>
8687
<dependency>

students/23K0687/23K0687-p21/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>23K0687</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0687-p21</artifactId>
12+
<description>Практическая 21 Кураев М М</description>
13+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package ru.mirea.practice.s0000001.num1;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.List;
6+
7+
public final class Main {
8+
public static void main(String[] args) {
9+
Object[] a = {1, "hello", 2, "world"};
10+
List<Object> l = toList(a);
11+
System.out.println("Конвертированный список: " + l);
12+
}
13+
14+
public static List<Object> toList(Object[] a) {
15+
List<Object> r = new ArrayList<>();
16+
Collections.addAll(r, a);
17+
return r;
18+
}
19+
20+
private Main() {
21+
throw new UnsupportedOperationException("Этот класс не предназначен для создания экземпляров");
22+
}
23+
}
24+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ru.mirea.practice.s0000001.num2;
2+
3+
public final class Main {
4+
public static void main(String[] args) {
5+
Object[] a = {1, 2L, 3.14, "hello"};
6+
MyArray m = new MyArray(a);
7+
m.printArray();
8+
}
9+
10+
private Main() {
11+
throw new UnsupportedOperationException("Этот класс не предназначен для создания экземпляров");
12+
}
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ru.mirea.practice.s0000001.num2;
2+
3+
public class MyArray {
4+
private Object[] arr;
5+
6+
public MyArray(Object[] arr) {
7+
this.arr = arr;
8+
}
9+
10+
public void printArray() {
11+
System.out.print("Массив: ");
12+
for (Object obj : arr) {
13+
System.out.print(obj + " ");
14+
}
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package ru.mirea.practice.s0000001.num3;
2+
3+
public final class Main {
4+
public static void main(String[] args) {
5+
Object[] a = {1, 2L, 3.14, "hello"};
6+
Object e = getElement(a, 2);
7+
System.out.println("Элемент на индексе 2: " + e);
8+
}
9+
10+
public static Object getElement(Object[] a, int idx) {
11+
return a[idx];
12+
}
13+
14+
private Main() {
15+
throw new UnsupportedOperationException("Этот класс не предназначен для создания экземпляров");
16+
}
17+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ru.mirea.practice.s0000001.num4;
2+
3+
import java.io.File;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
public final class Main {
8+
public static void main(String[] args) {
9+
List<String> f = listFiles("путь_к_каталогу");
10+
System.out.println("Первые 5 элементов:");
11+
for (int i = 0; i < Math.min(5, f.size()); i++) {
12+
System.out.println(f.get(i));
13+
}
14+
}
15+
16+
public static List<String> listFiles(String path) {
17+
File dir = new File(path);
18+
List<String> files = new ArrayList<>();
19+
if (dir.isDirectory()) {
20+
File[] fileList = dir.listFiles();
21+
if (fileList != null) {
22+
for (File file : fileList) {
23+
files.add(file.getName());
24+
}
25+
}
26+
}
27+
return files;
28+
}
29+
30+
private Main() {
31+
throw new UnsupportedOperationException("Этот класс не предназначен для создания экземпляров");
32+
}
33+
}
34+

students/23K0687/23K0687-p22/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>23K0687</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0687-p22</artifactId>
12+
<description>Практическая 22 Кураев М М</description>
13+
</project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package ru.mirea.practice.s0000001.num1;
2+
3+
import java.util.Stack;
4+
5+
public final class Main {
6+
public static void main(String[] args) {
7+
String[] e = {"2", "3", "+", "5", "*"};
8+
double r = evaluateReversePolishNotation(e);
9+
System.out.println("Результат: " + r);
10+
}
11+
12+
public static double evaluateReversePolishNotation(String[] e) {
13+
Stack<Double> s = new Stack<>();
14+
for (String t : e) {
15+
if (isNum(t)) {
16+
s.push(Double.parseDouble(t));
17+
} else {
18+
double b = s.pop();
19+
double a = s.pop();
20+
double res = applyOp(a, b, t);
21+
s.push(res);
22+
}
23+
}
24+
return s.pop();
25+
}
26+
27+
public static boolean isNum(String t) {
28+
try {
29+
Double.parseDouble(t);
30+
return true;
31+
} catch (NumberFormatException ex) {
32+
return false;
33+
}
34+
}
35+
36+
public static double applyOp(double a, double b, String op) {
37+
switch (op) {
38+
case "+":
39+
return a + b;
40+
case "-":
41+
return a - b;
42+
case "*":
43+
return a * b;
44+
case "/":
45+
return a / b;
46+
default:
47+
throw new IllegalArgumentException("Неизвестный оператор: " + op);
48+
}
49+
}
50+
51+
private Main() {
52+
throw new UnsupportedOperationException("Этот класс не предназначен для создания экземпляров");
53+
}
54+
}
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>23K0687</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0687-p23.a</artifactId>
12+
<description>Практическая 23 Кураев М М</description>
13+
</project>

0 commit comments

Comments
 (0)