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

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

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<module>students/23K0186</module>
<module>students/23K0755</module>
<module>students/23K1292</module>
<module>students/23K0687</module>
</modules>
<dependencies>
<dependency>
Expand Down
13 changes: 13 additions & 0 deletions students/23K0687/23K0687-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>23K0687</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0687-p21</artifactId>
<description>Практическая 21 Кураев М М</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ru.mirea.practice.s0000001.num1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public final class Main {
public static void main(String[] args) {
Object[] a = {1, "hello", 2, "world"};
List<Object> l = toList(a);
System.out.println("Конвертированный список: " + l);
}

public static List<Object> toList(Object[] a) {
List<Object> r = new ArrayList<>();
Collections.addAll(r, a);
return r;
}

private Main() {
throw new UnsupportedOperationException("Этот класс не предназначен для создания экземпляров");
}
}

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

public final class Main {
public static void main(String[] args) {
Object[] a = {1, 2L, 3.14, "hello"};
MyArray m = new MyArray(a);
m.printArray();
}

private Main() {
throw new UnsupportedOperationException("Этот класс не предназначен для создания экземпляров");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ru.mirea.practice.s0000001.num2;

public class MyArray {
private Object[] arr;

public MyArray(Object[] arr) {
this.arr = arr;
}

public void printArray() {
System.out.print("Массив: ");
for (Object obj : arr) {
System.out.print(obj + " ");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ru.mirea.practice.s0000001.num3;

public final class Main {
public static void main(String[] args) {
Object[] a = {1, 2L, 3.14, "hello"};
Object e = getElement(a, 2);
System.out.println("Элемент на индексе 2: " + e);
}

public static Object getElement(Object[] a, int idx) {
return a[idx];
}

private Main() {
throw new UnsupportedOperationException("Этот класс не предназначен для создания экземпляров");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ru.mirea.practice.s0000001.num4;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public final class Main {
public static void main(String[] args) {
List<String> f = listFiles("путь_к_каталогу");
System.out.println("Первые 5 элементов:");
for (int i = 0; i < Math.min(5, f.size()); i++) {
System.out.println(f.get(i));
}
}

public static List<String> listFiles(String path) {
File dir = new File(path);
List<String> files = new ArrayList<>();
if (dir.isDirectory()) {
File[] fileList = dir.listFiles();
if (fileList != null) {
for (File file : fileList) {
files.add(file.getName());
}
}
}
return files;
}

private Main() {
throw new UnsupportedOperationException("Этот класс не предназначен для создания экземпляров");
}
}

13 changes: 13 additions & 0 deletions students/23K0687/23K0687-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>23K0687</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0687-p22</artifactId>
<description>Практическая 22 Кураев М М</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package ru.mirea.practice.s0000001.num1;

import java.util.Stack;

public final class Main {
public static void main(String[] args) {
String[] e = {"2", "3", "+", "5", "*"};
double r = evaluateReversePolishNotation(e);
System.out.println("Результат: " + r);
}

public static double evaluateReversePolishNotation(String[] e) {
Stack<Double> s = new Stack<>();
for (String t : e) {
if (isNum(t)) {
s.push(Double.parseDouble(t));
} else {
double b = s.pop();
double a = s.pop();
double res = applyOp(a, b, t);
s.push(res);
}
}
return s.pop();
}

public static boolean isNum(String t) {
try {
Double.parseDouble(t);
return true;
} catch (NumberFormatException ex) {
return false;
}
}

public static double applyOp(double a, double b, String op) {
switch (op) {
case "+":
return a + b;
case "-":
return a - b;
case "*":
return a * b;
case "/":
return a / b;
default:
throw new IllegalArgumentException("Неизвестный оператор: " + op);
}
}

private Main() {
throw new UnsupportedOperationException("Этот класс не предназначен для создания экземпляров");
}
}
13 changes: 13 additions & 0 deletions students/23K0687/23K0687-p23.a/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>23K0687</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0687-p23.a</artifactId>
<description>Практическая 23 Кураев М М</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ru.mirea.practice.s0000001.num1;

public class ArrayQueue {
private int[] arr = new int[10];
private int h = 0;
private int t = 0;
private int sz = 0;

public void enqueue(int x) {
if (sz == arr.length) {
throw new IllegalStateException("Очередь переполнена");
}
arr[t] = x;
t = (t + 1) % arr.length;
sz++;
}

public int element() {
if (sz == 0) {
throw new IllegalStateException("Очередь пуста");
}
return arr[h];
}

public int dequeue() {
if (sz == 0) {
throw new IllegalStateException("Очередь пуста");
}
int res = arr[h];
h = (h + 1) % arr.length;
sz--;
return res;
}

public int size() {
return sz;
}

public boolean isEmpty() {
return sz == 0;
}

public void clear() {
h = 0;
t = 0;
sz = 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ru.mirea.practice.s0000001.num1;

public class ArrayQueueAdt {
private int[] arr = new int[10];
private int h = 0;
private int t = 0;
private int sz = 0;

public void enqueue(int x) {
if (sz == arr.length) {
throw new IllegalStateException("Очередь переполнена");
}
arr[t] = x;
t = (t + 1) % arr.length;
sz++;
}

public int element() {
if (sz == 0) {
throw new IllegalStateException("Очередь пуста");
}
return arr[h];
}

public int dequeue() {
if (sz == 0) {
throw new IllegalStateException("Очередь пуста");
}
int res = arr[h];
h = (h + 1) % arr.length;
sz--;
return res;
}

public int size() {
return sz;
}

public boolean isEmpty() {
return sz == 0;
}

public void clear() {
h = 0;
t = 0;
sz = 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ru.mirea.practice.s0000001.num1;

public final class ArrayQueueModule {
private ArrayQueueModule() {}

public static void enqueue(int x) {
// Реализация
}

public static int element() {
return 0;
}

public static int dequeue() {
return 0;
}

public static int size() {
return 0;
}

public static boolean isEmpty() {
return false;
}

public static void clear() {
// Метод пока не реализован
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ru.mirea.practice.s0000001.num1;

public final class Main {
private Main() {}

public static void main(String[] args) {
// Логика программы
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ru.mirea.practice.s0000001.num2;

public abstract class AbstractQueue implements Queue {
protected int sz = 0;

public int size() {
return sz;
}

public boolean isEmpty() {
return sz == 0;
}

public void clear() {
sz = 0;
}
}
Loading
Loading