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

Commit 4749714

Browse files
authored
Merge pull request #689 from w0RKintILDeaTH/lab21-32
Лабараторная работа №21-32
2 parents 4b8c2cb + b11e988 commit 4749714

File tree

70 files changed

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

70 files changed

+2094
-0
lines changed

students/23K0365/23K0365-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>23K0365</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0365-p21</artifactId>
12+
<description>Массивы</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.s0000001;
2+
3+
public final class Main {
4+
5+
private Main() {
6+
7+
}
8+
9+
public static void main(String[] args) {
10+
System.out.println("первая практическая работа!");
11+
}
12+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.Set;
6+
import java.util.Map;
7+
import java.util.HashMap;
8+
import java.util.HashSet;
9+
10+
public class Solution<T, K, V> { // Integer, String, Boolean
11+
public List<T> newList(T... elements) {
12+
return new ArrayList<>(java.util.Arrays.asList(elements));
13+
}
14+
15+
public Set<T> newHS(T... elements) {
16+
return new HashSet<>(java.util.Arrays.asList(elements));
17+
}
18+
19+
public Map<K, V> newHM(K[] keys, V[] values) {
20+
if (keys.length != values.length) {
21+
System.exit(0);
22+
}
23+
Map<K, V> a = new HashMap<>();
24+
for (int i = 0; i < keys.length; i++) {
25+
a.put(keys[i], values[i]);
26+
}
27+
return a;
28+
}
29+
30+
public static void main(String[] args) {
31+
Solution<Integer, String, Boolean> me = new Solution<>();
32+
String[] k = {"0", "wow", "yeah", "etc"};
33+
Boolean[] v = {true, false, true, true};
34+
List<Integer> myLst = me.newList(12, 15, 523, 235);
35+
Set<Integer> urSet = me.newHS(12, 15, 523, 235);
36+
Map<String, Boolean> ourMap = me.newHM(k, v);
37+
System.out.println(urSet.contains(124));
38+
System.out.println(myLst.get(0));
39+
System.out.println(ourMap.get("wow"));
40+
}
41+
}
42+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.Arrays;
4+
import java.util.LinkedList;
5+
import java.util.List;
6+
7+
public class TaskFour<T> {
8+
List<T> myLst = new LinkedList<>();
9+
10+
public void saveCatalog(T... args) {
11+
myLst.addAll(Arrays.asList(args));
12+
}
13+
14+
public void getFive() {
15+
for (int i = 0; i < 5; i++) {
16+
System.out.print(myLst.get(i) + " ");
17+
}
18+
}
19+
20+
public static void main(String[] args) {
21+
TaskFour<Boolean> a = new TaskFour<>();
22+
a.saveCatalog(true,false,true,true,true,false,
23+
true,true,false,true,true,true,false,true);
24+
a.getFive();
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.Arrays;
4+
import java.util.LinkedList;
5+
import java.util.List;
6+
7+
public class TaskOne<T> {
8+
private final T[] arr;
9+
10+
public TaskOne(T[] arr) {
11+
this.arr = arr;
12+
}
13+
14+
public List<T> getUrList() {
15+
return new LinkedList<>(Arrays.asList(arr));
16+
}
17+
18+
public static void main(String[] args) {
19+
String[] strs = {"q","qw","qwe","qwer"};
20+
Integer[] ints = {1,2,3,4,5};
21+
TaskOne a = new TaskOne(strs);
22+
System.out.println(a.getUrList().get(0));
23+
TaskOne b = new TaskOne(ints);
24+
System.out.println(b.getUrList().get(0));
25+
}
26+
}
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+
public class TaskThree<T> {
4+
private T[] anotherArr;
5+
6+
public TaskThree(T[] anotherArr) {
7+
this.anotherArr = anotherArr;
8+
}
9+
10+
public T getEl(int index) {
11+
return anotherArr[index];
12+
}
13+
14+
public static void main(String[] args) {
15+
Boolean[] bools = {true,false,true};
16+
Short[] shortPeople = {-32760,-32761,-32762};
17+
TaskThree<Boolean> a = new TaskThree(bools);
18+
TaskThree<Short> b = new TaskThree(shortPeople);
19+
System.out.println(a.getEl(2));
20+
System.out.println(b.getEl(2));
21+
}
22+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public class TaskTwo<T> {
4+
private T[] urArr;
5+
6+
public TaskTwo(T[] urArr) {
7+
this.urArr = urArr;
8+
}
9+
10+
public void knowType() {
11+
System.out.println(urArr.getClass().getName());
12+
}
13+
14+
public static void main(String[] args) {
15+
String[] strs = {"q","qw","qwe","qwer"};
16+
Integer[] ints = {1,2,3,4,5};
17+
Boolean[] bools = {true,false,true};
18+
Short[] shortPeople = {-32760,-32761,-32762};
19+
TaskTwo a = new TaskTwo(strs);
20+
TaskTwo b = new TaskTwo(ints);
21+
TaskTwo c = new TaskTwo(bools);
22+
final TaskTwo d = new TaskTwo(shortPeople);
23+
a.knowType();
24+
b.knowType();
25+
c.knowType();
26+
d.knowType();
27+
}
28+
}

students/23K0365/23K0365-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>23K0365</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0365-p22</artifactId>
12+
<description>Массивы</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.s0000001;
2+
3+
public final class Main {
4+
5+
private Main() {
6+
7+
}
8+
9+
public static void main(String[] args) {
10+
System.out.println("первая практическая работа!");
11+
}
12+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.ArrayDeque;
4+
import java.util.Deque;
5+
6+
public abstract class Pln {
7+
private static boolean isOperate(String token) {
8+
return "+".equals(token) || "-".equals(token) || "*".equals(token) || "/".equals(token) || "^".equals(token);
9+
}
10+
11+
private static double operationChoose(double a, double b, String op) {
12+
switch (op) {
13+
case "+": return a + b;
14+
case "-": return a - b;
15+
case "*": return a * b;
16+
case "/":
17+
if (b == 0) {
18+
throw new ArithmeticException("INFINITY");
19+
}
20+
return a / b;
21+
default: return Double.NaN;
22+
}
23+
}
24+
25+
public static double calculateSmth(String... args) {
26+
Deque<Double> st = new ArrayDeque<>();
27+
for (String one : args) {
28+
try {
29+
double temp = Double.parseDouble(one);
30+
st.push(temp);
31+
} catch (NumberFormatException e) {
32+
if (isOperate(one)) {
33+
if (st.size() < 2) {
34+
System.err.println("too litle amount of opearnds: " + one);
35+
return Double.NaN;
36+
}
37+
double x = st.pop();
38+
double y = st.pop();
39+
try {
40+
st.push(operationChoose(y, x, one));
41+
} catch (ArithmeticException ae) {
42+
System.err.println("error: ");
43+
return Double.NaN;
44+
}
45+
} else {
46+
System.err.println("uncorrect symbol: " + one);
47+
return Double.NaN;
48+
}
49+
} catch (Exception e) {
50+
System.err.println("incorrect symbols");
51+
return Double.NaN;
52+
}
53+
}
54+
55+
if (st.size() != 1) {
56+
System.err.println("error");
57+
return Double.NaN;
58+
}
59+
return st.pop();
60+
}
61+
62+
public static void main(String[] args) {
63+
String[] a = {"2", "3", "*", "4", "5", "*", "+"};
64+
String[] b = {"2", "3", "4", "5", "6", "*", "+", "-", "/"};
65+
System.out.println(calculateSmth(a));
66+
System.out.println(calculateSmth(b));
67+
}
68+
}
69+

0 commit comments

Comments
 (0)