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

Commit 1aee80c

Browse files
authored
Merge pull request #648 from or0kalame/feature/pract26-32
Практические №26-32
2 parents d1f1704 + 8f62f91 commit 1aee80c

File tree

69 files changed

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

69 files changed

+2199
-0
lines changed

PROCS.TXT

Whitespace-only changes.

students/23K0112/23K0112-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>23K0112</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0112-p21</artifactId>
12+
<description>Стирание типов в Джава</description>
13+
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package ru.mirea.practice.s29k0112;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
7+
public abstract class ArrayToListConverter {
8+
public static <E> List<E> convertArrayToList(E[] array) {
9+
return new ArrayList<>(Arrays.asList(array));
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ru.mirea.practice.s29k0112;
2+
3+
public abstract class IndexGetter<E> {
4+
public static <E> E getElement(E[] array, int index) {
5+
if (index < 0 || index >= array.length) {
6+
throw new IndexOutOfBoundsException("Индекс выходит за границу");
7+
}
8+
return array[index];
9+
}
10+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ru.mirea.practice.s29k0112;
2+
3+
import java.util.List;
4+
5+
public final class TestMethods {
6+
private TestMethods() {
7+
8+
}
9+
10+
public static void main(String[] args) {
11+
String[] stringArray = {"один", "два", "три"};
12+
List<String> stringList = ArrayToListConverter.convertArrayToList(stringArray);
13+
System.out.println(stringList);
14+
15+
System.out.println(IndexGetter.getElement(stringArray, 0));
16+
System.out.println(IndexGetter.getElement(stringArray, 1));
17+
}
18+
}

students/23K0112/23K0112-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>23K0112</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0112-p22</artifactId>
12+
<description>Абстрактные типы данных. Стек</description>
13+
</project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package ru.mirea.practice.s29k0112;
2+
3+
public class RpnCalculator {
4+
private Stack stack;
5+
6+
public RpnCalculator(int size) {
7+
stack = new Stack(size);
8+
}
9+
10+
public double calculate(String expression) throws Exception {
11+
String[] tokens = expression.split(" ");
12+
13+
for (String token : tokens) {
14+
switch (token) {
15+
case "+":
16+
stack.push(stack.pop() + stack.pop());
17+
break;
18+
case "-":
19+
double subtrahend = stack.pop();
20+
stack.push(stack.pop() - subtrahend);
21+
break;
22+
case "*":
23+
stack.push(stack.pop() * stack.pop());
24+
break;
25+
case "/":
26+
double divisor = stack.pop();
27+
if (divisor == 0) {
28+
throw new ArithmeticException("Division by zero");
29+
}
30+
stack.push(stack.pop() / divisor);
31+
break;
32+
default:
33+
stack.push(Double.parseDouble(token));
34+
}
35+
}
36+
37+
return stack.pop();
38+
}
39+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package ru.mirea.practice.s29k0112;
2+
3+
class Stack {
4+
private double[] arr;
5+
private int top;
6+
private int capacity;
7+
8+
Stack(int size) {
9+
arr = new double[size];
10+
capacity = size;
11+
top = -1;
12+
}
13+
14+
public void push(double x) {
15+
if (isFull()) {
16+
System.out.println("Stack OverFlow");
17+
System.exit(1);
18+
}
19+
arr[++top] = x;
20+
}
21+
22+
public double pop() {
23+
if (isEmpty()) {
24+
System.out.println("STACK EMPTY");
25+
System.exit(1);
26+
}
27+
return arr[top--];
28+
}
29+
30+
public int getSize() {
31+
return top + 1;
32+
}
33+
34+
public Boolean isEmpty() {
35+
return top == -1;
36+
}
37+
38+
public Boolean isFull() {
39+
return top == capacity - 1;
40+
}
41+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ru.mirea.practice.s29k0112;
2+
3+
public final class TestCalculator {
4+
private TestCalculator() {
5+
6+
}
7+
8+
public static void main(String[] args) throws Exception {
9+
RpnCalculator calculator = new RpnCalculator(10);
10+
System.out.println("1 2 + = " + calculator.calculate("1 2 +"));
11+
System.out.println("2 3 * 4 5 * + = " + calculator.calculate("2 3 * 4 5 * +"));
12+
System.out.println("2 3 4 5 6 * + - / = " + calculator.calculate("2 3 4 5 6 * + - /"));
13+
14+
try {
15+
System.out.println("1 0 / = " + calculator.calculate("1 0 /"));
16+
} catch (ArithmeticException e) {
17+
System.out.println(e.getMessage());
18+
}
19+
}
20+
}

students/23K0112/23K0112-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>23K0112</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0112-p23</artifactId>
12+
<description>Абстрактные типы данных. Очередь</description>
13+
</project>

0 commit comments

Comments
 (0)