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

Лабараторная работа №21-32 #689

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions students/23K0365/23K0365-p21/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0365</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0365-p21</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.mirea.practice.s0000001;

public final class Main {

private Main() {

}

public static void main(String[] args) {
System.out.println("первая практическая работа!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ru.mirea.practice.s0000001;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
import java.util.HashSet;

public class Solution<T, K, V> { // Integer, String, Boolean
public List<T> newList(T... elements) {
return new ArrayList<>(java.util.Arrays.asList(elements));
}

public Set<T> newHS(T... elements) {
return new HashSet<>(java.util.Arrays.asList(elements));
}

public Map<K, V> newHM(K[] keys, V[] values) {
if (keys.length != values.length) {
System.exit(0);
}
Map<K, V> a = new HashMap<>();
for (int i = 0; i < keys.length; i++) {
a.put(keys[i], values[i]);
}
return a;
}

public static void main(String[] args) {
Solution<Integer, String, Boolean> me = new Solution<>();
String[] k = {"0", "wow", "yeah", "etc"};
Boolean[] v = {true, false, true, true};
List<Integer> myLst = me.newList(12, 15, 523, 235);
Set<Integer> urSet = me.newHS(12, 15, 523, 235);
Map<String, Boolean> ourMap = me.newHM(k, v);
System.out.println(urSet.contains(124));
System.out.println(myLst.get(0));
System.out.println(ourMap.get("wow"));
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.mirea.practice.s0000001;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class TaskFour<T> {
List<T> myLst = new LinkedList<>();

public void saveCatalog(T... args) {
myLst.addAll(Arrays.asList(args));
}

public void getFive() {
for (int i = 0; i < 5; i++) {
System.out.print(myLst.get(i) + " ");
}
}

public static void main(String[] args) {
TaskFour<Boolean> a = new TaskFour<>();
a.saveCatalog(true,false,true,true,true,false,
true,true,false,true,true,true,false,true);
a.getFive();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.mirea.practice.s0000001;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class TaskOne<T> {
private final T[] arr;

public TaskOne(T[] arr) {
this.arr = arr;
}

public List<T> getUrList() {
return new LinkedList<>(Arrays.asList(arr));
}

public static void main(String[] args) {
String[] strs = {"q","qw","qwe","qwer"};
Integer[] ints = {1,2,3,4,5};
TaskOne a = new TaskOne(strs);
System.out.println(a.getUrList().get(0));
TaskOne b = new TaskOne(ints);
System.out.println(b.getUrList().get(0));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ru.mirea.practice.s0000001;

public class TaskThree<T> {
private T[] anotherArr;

public TaskThree(T[] anotherArr) {
this.anotherArr = anotherArr;
}

public T getEl(int index) {
return anotherArr[index];
}

public static void main(String[] args) {
Boolean[] bools = {true,false,true};
Short[] shortPeople = {-32760,-32761,-32762};
TaskThree<Boolean> a = new TaskThree(bools);
TaskThree<Short> b = new TaskThree(shortPeople);
System.out.println(a.getEl(2));
System.out.println(b.getEl(2));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ru.mirea.practice.s0000001;

public class TaskTwo<T> {
private T[] urArr;

public TaskTwo(T[] urArr) {
this.urArr = urArr;
}

public void knowType() {
System.out.println(urArr.getClass().getName());
}

public static void main(String[] args) {
String[] strs = {"q","qw","qwe","qwer"};
Integer[] ints = {1,2,3,4,5};
Boolean[] bools = {true,false,true};
Short[] shortPeople = {-32760,-32761,-32762};
TaskTwo a = new TaskTwo(strs);
TaskTwo b = new TaskTwo(ints);
TaskTwo c = new TaskTwo(bools);
final TaskTwo d = new TaskTwo(shortPeople);
a.knowType();
b.knowType();
c.knowType();
d.knowType();
}
}
13 changes: 13 additions & 0 deletions students/23K0365/23K0365-p22/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0365</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0365-p22</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.mirea.practice.s0000001;

public final class Main {

private Main() {

}

public static void main(String[] args) {
System.out.println("первая практическая работа!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package ru.mirea.practice.s0000001;

import java.util.ArrayDeque;
import java.util.Deque;

public abstract class Pln {
private static boolean isOperate(String token) {
return "+".equals(token) || "-".equals(token) || "*".equals(token) || "/".equals(token) || "^".equals(token);
}

private static double operationChoose(double a, double b, String op) {
switch (op) {
case "+": return a + b;
case "-": return a - b;
case "*": return a * b;
case "/":
if (b == 0) {
throw new ArithmeticException("INFINITY");
}
return a / b;
default: return Double.NaN;
}
}

public static double calculateSmth(String... args) {
Deque<Double> st = new ArrayDeque<>();
for (String one : args) {
try {
double temp = Double.parseDouble(one);
st.push(temp);
} catch (NumberFormatException e) {
if (isOperate(one)) {
if (st.size() < 2) {
System.err.println("too litle amount of opearnds: " + one);
return Double.NaN;
}
double x = st.pop();
double y = st.pop();
try {
st.push(operationChoose(y, x, one));
} catch (ArithmeticException ae) {
System.err.println("error: ");
return Double.NaN;
}
} else {
System.err.println("uncorrect symbol: " + one);
return Double.NaN;
}
} catch (Exception e) {
System.err.println("incorrect symbols");
return Double.NaN;
}
}

if (st.size() != 1) {
System.err.println("error");
return Double.NaN;
}
return st.pop();
}

public static void main(String[] args) {
String[] a = {"2", "3", "*", "4", "5", "*", "+"};
String[] b = {"2", "3", "4", "5", "6", "*", "+", "-", "/"};
System.out.println(calculateSmth(a));
System.out.println(calculateSmth(b));
}
}

13 changes: 13 additions & 0 deletions students/23K0365/23K0365-p23/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0365</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0365-p23</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.mirea.practice.s0000001;

public final class Main {

private Main() {

}

public static void main(String[] args) {
System.out.println("первая практическая работа!");
}
}
Loading
Loading