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

Commit 1f66dff

Browse files
authored
Merge pull request #694 from evoliatra/labs21-32
Labs21-32
2 parents 5319834 + f0eac6f commit 1f66dff

File tree

39 files changed

+802
-0
lines changed

39 files changed

+802
-0
lines changed

students/23K9901/23K9901-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>23K9901</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K9901-p21</artifactId>
12+
<description>Второе задание</description>
13+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public class ArrayElementGetter<T> {
4+
private T[] array;
5+
6+
public ArrayElementGetter(T[] array) {
7+
this.array = array;
8+
}
9+
10+
public T getElementByIndex(int index) {
11+
if (index < 0 || index >= array.length) {
12+
throw new IndexOutOfBoundsException("Invalid index: " + index);
13+
}
14+
return array[index];
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
abstract class Main {
4+
public static void main(String[] args) {
5+
Integer[] numbers = {10, 20, 30, 40, 50};
6+
ArrayElementGetter<Integer> intGetter = new ArrayElementGetter<>(numbers);
7+
System.out.println("Элемент по индексу 2: " + intGetter.getElementByIndex(2));
8+
9+
String[] words = {"apple", "banana", "cherry"};
10+
ArrayElementGetter<String> stringGetter = new ArrayElementGetter<>(words);
11+
System.out.println("Элемент по индексу 1: " + stringGetter.getElementByIndex(1));
12+
}
13+
}

students/23K9901/23K9901-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>23K9901</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K9901-p22</artifactId>
12+
<description>Второе задание</description>
13+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public class ArrayElementGetter<T> {
4+
private T[] array;
5+
6+
public ArrayElementGetter(T[] array) {
7+
this.array = array;
8+
}
9+
10+
public T getElementByIndex(int index) {
11+
if (index < 0 || index >= array.length) {
12+
throw new IndexOutOfBoundsException("Invalid index: " + index);
13+
}
14+
return array[index];
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
abstract class Main3 {
4+
public static void main(String[] args) {
5+
Integer[] numbers = {10, 20, 30, 40, 50};
6+
ArrayElementGetter<Integer> intGetter = new ArrayElementGetter<>(numbers);
7+
System.out.println("Элемент по индексу 2: " + intGetter.getElementByIndex(2));
8+
9+
String[] words = {"apple", "banana", "cherry"};
10+
ArrayElementGetter<String> stringGetter = new ArrayElementGetter<>(words);
11+
System.out.println("Элемент по индексу 1: " + stringGetter.getElementByIndex(1));
12+
}
13+
}

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

students/23K9901/23K9901-p24/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>23K9901</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K9901-p24</artifactId>
12+
<description>Второе задание</description>
13+
</project>

0 commit comments

Comments
 (0)