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

Commit b1bdeca

Browse files
authored
Merge pull request #669 from dendrokton/features/lab21
Лабораторная 21-32
2 parents f70b8a6 + 751b081 commit b1bdeca

File tree

56 files changed

+1373
-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.

56 files changed

+1373
-0
lines changed

students/23K0130/23K0130-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="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>23K0130</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0130-p21</artifactId>
12+
<description>21 задание</description>
13+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.mirea.practice.s23k0130;
2+
3+
public final class Main {
4+
5+
private Main() {
6+
7+
}
8+
9+
public static void main(String[] args) {
10+
System.out.println("21 практическая работа");
11+
}
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package ru.mirea.practice.s23k0130.task1;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public abstract class Main {
7+
public static <T> List<T> arrayToArrayList(T[] array) {
8+
List<T> list = new ArrayList<>();
9+
for (T element : array) {
10+
list.add(element);
11+
}
12+
return list;
13+
}
14+
15+
public static void main(String[] args) {
16+
Integer[] arrayInt = {0, 1, 0, 2, 0, 6};
17+
List<Integer> listInt = arrayToArrayList(arrayInt);
18+
System.out.println(listInt);
19+
20+
String[] arrayStr = {"square", "triangle", "rectangle", "circle"};
21+
List<String> listStr = arrayToArrayList(arrayStr);
22+
System.out.println(listStr);
23+
24+
}
25+
}

students/23K0130/23K0130-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="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>23K0130</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0130-p22</artifactId>
12+
<description>22 задание</description>
13+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.mirea.practice.s23k0130;
2+
3+
public final class Main {
4+
5+
private Main() {
6+
7+
}
8+
9+
public static void main(String[] args) {
10+
System.out.println("22 практическая работа");
11+
}
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ru.mirea.practice.s23k0130.task1;
2+
3+
abstract class Main {
4+
public static void main(String[] args) {
5+
String rpnExpression = "3 9 + 4 * 2 /";
6+
double result = RPncalculator.calculate(rpnExpression);
7+
System.out.println("Результат: " + result);
8+
}
9+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package ru.mirea.practice.s23k0130.task1;
2+
3+
import java.util.Stack;
4+
5+
abstract class RPncalculator {
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+
}

students/23K0130/23K0130-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="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>23K0130</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0130-p23</artifactId>
12+
<description>23 задание</description>
13+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.mirea.practice.s23k0130;
2+
3+
public final class Main {
4+
5+
private Main() {
6+
7+
}
8+
9+
public static void main(String[] args) {
10+
System.out.println("23 практическая работа");
11+
}
12+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package ru.mirea.practice.s23k0130.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 element() {
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)