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

Commit 779c268

Browse files
authored
Merge pull request #661 from seledkaoff/features/lab29-32
Features/lab29 32
2 parents 3fe29ab + f8c4c01 commit 779c268

File tree

34 files changed

+768
-0
lines changed

34 files changed

+768
-0
lines changed

students/23K0351/23K0351-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>23K0351</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0351-p21</artifactId>
12+
<description>/</description>
13+
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
7+
public abstract class First {
8+
public static List<Object> convertArrayToList(Object[] array) {
9+
return new ArrayList<>(Arrays.asList(array));
10+
}
11+
12+
public static void main(String[] args) {
13+
String[] stringArray = {"one", "two", "three"};
14+
Integer[] intArray = {1, 2, 3};
15+
16+
List<Object> stringList = convertArrayToList(stringArray);
17+
List<Object> intList = convertArrayToList(intArray);
18+
19+
System.out.println("String List: " + stringList);
20+
System.out.println("Integer List: " + intList);
21+
}
22+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class GenericArray<T> {
7+
private List<T> elements;
8+
9+
public GenericArray() {
10+
elements = new ArrayList<>();
11+
}
12+
13+
public void addElement(T element) {
14+
elements.add(element);
15+
}
16+
17+
public List<T> getElements() {
18+
return elements;
19+
}
20+
21+
public static void main(String[] args) {
22+
GenericArray<Integer> intArray = new GenericArray<>();
23+
intArray.addElement(1);
24+
intArray.addElement(2);
25+
intArray.addElement(3);
26+
27+
GenericArray<String> stringArray = new GenericArray<>();
28+
stringArray.addElement("Hello");
29+
stringArray.addElement("World");
30+
31+
System.out.println("Integer Array: " + intArray.getElements());
32+
System.out.println("String Array: " + stringArray.getElements());
33+
}
34+
}

students/23K0351/23K0351-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>23K0351</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0351-p22</artifactId>
12+
<description>/</description>
13+
</project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.Stack;
4+
5+
public abstract class First {
6+
7+
public static double evaluate(String expression) {
8+
Stack<Double> stack = new Stack<>();
9+
String[] tokens = expression.split(" ");
10+
11+
for (String token : tokens) {
12+
switch (token) {
13+
case "+":
14+
stack.push(stack.pop() + stack.pop());
15+
break;
16+
case "-":
17+
double subtrahend = stack.pop();
18+
double minuend = stack.pop();
19+
stack.push(minuend - subtrahend);
20+
break;
21+
case "*":
22+
stack.push(stack.pop() * stack.pop());
23+
break;
24+
case "/":
25+
double divisor = stack.pop();
26+
double dividend = stack.pop();
27+
stack.push(dividend / divisor);
28+
break;
29+
default:
30+
stack.push(Double.parseDouble(token));
31+
break;
32+
}
33+
}
34+
35+
return stack.pop();
36+
}
37+
38+
public static void main(String[] args) {
39+
String expression = "1 2 + 3 * 4 /"; // (1 + 2) * 3 / 4
40+
double result = evaluate(expression);
41+
System.out.println("Результат: " + result);
42+
}
43+
}

students/23K0351/23K0351-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>23K0351</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0351-p24</artifactId>
12+
<description>/</description>
13+
</project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public interface Chair {
4+
void sit();
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public interface ChairFactory {
4+
Chair createChair();
5+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public class Client {
4+
private Chair chair;
5+
6+
public Client(ChairFactory factory) {
7+
this.chair = factory.createChair();
8+
}
9+
10+
public void sit() {
11+
chair.sit();
12+
}
13+
14+
public static void main(String[] args) {
15+
Client client1 = new Client(new VictorianChairFactory());
16+
client1.sit();
17+
18+
Client client2 = new Client(new MultifunctionalChairFactory());
19+
client2.sit();
20+
21+
Client client3 = new Client(new MagicalChairFactory());
22+
client3.sit();
23+
}
24+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public class MagicalChair implements Chair {
4+
@Override
5+
public void sit() {
6+
System.out.println("Сидите на магическом стуле.");
7+
}
8+
}

0 commit comments

Comments
 (0)