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

Commit 4ad3292

Browse files
authored
Merge branch 'main' into lab21-32
2 parents a73a17f + 0dfae01 commit 4ad3292

File tree

943 files changed

+30799
-117
lines changed

Some content is hidden

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

943 files changed

+30799
-117
lines changed

pom.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
<maven.compiler.source>11</maven.compiler.source>
1515
<maven.compiler.target>11</maven.compiler.target>
16-
<version.junit>1.11.3</version.junit>
17-
<version.jupiter>5.11.3</version.jupiter>
16+
<version.junit>1.11.4</version.junit>
17+
<version.jupiter>5.11.4</version.jupiter>
1818
<version.pmd>6.52.0</version.pmd>
1919
</properties>
2020

@@ -30,6 +30,7 @@
3030
<module>students/23K0135</module>
3131
<module>students/23K0623</module>
3232
<module>students/0000001</module>
33+
<module>students/23K9006</module>
3334
<module>students/23K0093</module>
3435
<module>students/23K0690</module>
3536
<module>students/23K0120</module>
@@ -82,6 +83,8 @@
8283
<module>students/23K0755</module>
8384
<module>students/23K1292</module>
8485
<module>students/23K0687</module>
86+
<module>students/23L0908</module>
87+
<module>students/23K0342</module>
8588
</modules>
8689
<dependencies>
8790
<dependency>
@@ -148,7 +151,7 @@
148151
<dependency>
149152
<groupId>com.puppycrawl.tools</groupId>
150153
<artifactId>checkstyle</artifactId>
151-
<version>10.20.1</version>
154+
<version>10.21.0</version>
152155
</dependency>
153156
</dependencies>
154157
<configuration>

students/23K0087/23K0087-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>23K0087</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0087-p21</artifactId>
12+
<description>Двадцать первое задание</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.s23k0087.task1;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
public abstract class ArrayToList {
7+
8+
public static <E> List<E> convertArrayToList(E[] array) {
9+
return Arrays.asList(array);
10+
}
11+
12+
public static void main(String[] args) {
13+
String[] arrayStr = {"Прибыл", "Сатору", "Годжо"};
14+
List<String> listStr = convertArrayToList(arrayStr);
15+
System.out.println("List String: " + listStr);
16+
17+
Integer[] arrayInt = {2, 0, 3, 1};
18+
List<Integer> listInt = convertArrayToList(arrayInt);
19+
System.out.println("List Integer: " + listInt);
20+
}
21+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package ru.mirea.practice.s23k0087.tasks2and3;
2+
3+
public class GenericArr<E> {
4+
private final E[] array;
5+
6+
public GenericArr(E[] elements) {
7+
this.array = elements;
8+
}
9+
10+
public E get(int index) {
11+
12+
if (index >= 0 && index < array.length) {
13+
return array[index];
14+
} else {
15+
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + array.length);
16+
}
17+
}
18+
19+
public void set(int index, E element) {
20+
if (index >= 0 && index < array.length) {
21+
array[index] = element;
22+
} else {
23+
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + array.length);
24+
}
25+
}
26+
27+
public E getElementByIndex(int index) {
28+
if (index < 0 || index >= array.length) {
29+
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + array.length);
30+
}
31+
return array[index];
32+
}
33+
34+
@Override
35+
public String toString() {
36+
StringBuilder sb = new StringBuilder("[");
37+
for (int i = 0; i < array.length; i++) {
38+
sb.append(array[i]);
39+
if (i < array.length - 1) {
40+
sb.append(", ");
41+
}
42+
}
43+
sb.append("]");
44+
return sb.toString();
45+
}
46+
47+
public int size() {
48+
return array.length;
49+
}
50+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package ru.mirea.practice.s23k0087.tasks2and3;
2+
3+
public abstract class Tester {
4+
public static void main(String[] args) {
5+
String[] arrayStr = {"Volkswagen", "Das", "Auto"};
6+
GenericArr<String> stringGenericArr = new GenericArr<>(arrayStr);
7+
System.out.println(stringGenericArr);
8+
9+
Long[] arrayLong = {2031L, 911922L, 1234567890L};
10+
GenericArr<Long> longGenericArr = new GenericArr<>(arrayLong);
11+
System.out.println(longGenericArr);
12+
13+
Double[] arrayDouble = {20.31, 0.19293912, 0.41413, 0.221};
14+
GenericArr<Double> doubleGenericArr = new GenericArr<>(arrayDouble);
15+
System.out.println(doubleGenericArr);
16+
}
17+
}

students/23K0087/23K0087-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>23K0087</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0087-p22</artifactId>
12+
<description>Двадцать второе задание</description>
13+
</project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package ru.mirea.practice.s23k0087.task1;
2+
3+
import java.util.Stack;
4+
5+
public abstract class Calculator {
6+
private static double applyOperation(double a, double b, String operator) {
7+
switch (operator) {
8+
case "+":
9+
return a + b;
10+
case "-":
11+
return a - b;
12+
case "*":
13+
return a * b;
14+
case "/":
15+
if (b == 0) {
16+
throw new ArithmeticException("Деление на ноль");
17+
}
18+
return a / b;
19+
default:
20+
throw new IllegalArgumentException("Недопустимый оператор: " + operator);
21+
}
22+
}
23+
24+
private static boolean isOperator(String token) {
25+
return "+".equals(token) || "-".equals(token) || "*".equals(token) || "/".equals(token);
26+
}
27+
28+
public static double calculate(String expression) {
29+
Stack<Double> stack = new Stack<>();
30+
String[] tokens = expression.split("\\s+");
31+
for (String token : tokens) {
32+
if (isOperator(token)) {
33+
double b = stack.pop();
34+
double a = stack.pop();
35+
stack.push(applyOperation(a, b, token));
36+
} else {
37+
stack.push(Double.parseDouble(token));
38+
}
39+
}
40+
return stack.pop();
41+
}
42+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ru.mirea.practice.s23k0087.task1;
2+
3+
public abstract class Tester {
4+
public static void main(String[] args) {
5+
String expression = "4 8 - 2 / 7 *";
6+
System.out.println("Calculating ((4 - 8) / 2) * 7");
7+
double result = Calculator.calculate(expression);
8+
System.out.println("Result: " + result);
9+
}
10+
}

students/23K0087/23K0087-p23/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>23K0087</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0087-p23</artifactId>
12+
<description>Двадцать третье задание</description>
13+
</project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package ru.mirea.practice.s23k0087.task1;
2+
3+
public final class ArrayQueue {
4+
5+
private Object[] queue = new Object[16];
6+
private int head = 0;
7+
private int tail = 0;
8+
private int size = 0;
9+
10+
public static ArrayQueue createQueue() {
11+
return new ArrayQueue();
12+
}
13+
14+
public void enqueue(Object element) {
15+
ensureCapacity(size + 1);
16+
queue[tail] = element;
17+
tail = (tail + 1) % queue.length;
18+
size++;
19+
}
20+
21+
public Object getFirstElement() {
22+
return queue[head];
23+
}
24+
25+
public Object dequeue() {
26+
Object result;
27+
result = queue[head];
28+
queue[head] = null;
29+
head = (head + 1) % queue.length;
30+
size--;
31+
return result;
32+
}
33+
34+
public int size() {
35+
return size;
36+
}
37+
38+
public boolean isEmpty() {
39+
return size == 0;
40+
}
41+
42+
public void clear() {
43+
queue = new Object[16];
44+
head = tail = size = 0;
45+
}
46+
47+
private void ensureCapacity(int capacity) {
48+
if (capacity > queue.length) {
49+
Object[] newQueue = new Object[queue.length * 2];
50+
for (int i = 0; i < size; i++) {
51+
newQueue[i] = queue[(head + i) % queue.length];
52+
}
53+
queue = newQueue;
54+
head = 0;
55+
tail = size;
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)