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

Commit 9dd3da6

Browse files
authored
Merge pull request #628 from AlexandraNabieva/main
Лабораторные №21-32
2 parents 50b3dfd + 88aa1f9 commit 9dd3da6

File tree

68 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.

68 files changed

+2094
-0
lines changed

students/23K0169/23K0169-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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>23K0169</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0169-p21</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ru.mirea.practice.s23k0169.t1;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
public abstract class Converter {
7+
public static <T> List<T> convertArrayToList(T[] array) {
8+
return Arrays.asList(array);
9+
}
10+
11+
public static void main(String[] args) {
12+
String[] stringArray = {"a", "b", "c"};
13+
List<String> stringList = convertArrayToList(stringArray);
14+
System.out.println("Список строк: " + stringList);
15+
16+
Integer[] intArray = {1, 2, 3};
17+
List<Integer> intList = convertArrayToList(intArray);
18+
System.out.println("Список чисел: " + intList);
19+
}
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ru.mirea.practice.s23k0169.t2;
2+
3+
public class GenericArray<T> {
4+
private T[] array;
5+
6+
public GenericArray(T[] array) {
7+
this.array = array;
8+
}
9+
10+
public T[] getArray() {
11+
return array;
12+
}
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package ru.mirea.practice.s23k0169.t2;
2+
3+
public abstract class Main {
4+
public static void main(String[] args) {
5+
Integer[] intArray = {1, 2, 3, 4, 5};
6+
GenericArray<Integer> integerArray = new GenericArray<>(intArray);
7+
8+
System.out.println("Массив целых чисел:");
9+
for (Integer element : integerArray.getArray()) {
10+
System.out.println(element);
11+
}
12+
13+
String[] stringArray = {"apple", "banana", "cherry"};
14+
GenericArray<String> stringGenericArray = new GenericArray<>(stringArray);
15+
16+
System.out.println("\nМассив строк:");
17+
for (String element : stringGenericArray.getArray()) {
18+
System.out.println(element);
19+
}
20+
}
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ru.mirea.practice.s23k0169.t3;
2+
3+
public class GenericArray<T> {
4+
private T[] array;
5+
6+
public GenericArray(T[] array) {
7+
this.array = array;
8+
}
9+
10+
public T[] getArray() {
11+
return array;
12+
}
13+
14+
public T getElementByIndex(int index) {
15+
if (index < 0 || index >= array.length) {
16+
throw new IndexOutOfBoundsException("Индекс выходит за пределы массива");
17+
}
18+
return array[index];
19+
}
20+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package ru.mirea.practice.s23k0169.t3;
2+
3+
public abstract class Main {
4+
public static void main(String[] args) {
5+
Integer[] intArray = {1, 2, 3, 4, 5};
6+
GenericArray<Integer> integerArray = new GenericArray<>(intArray);
7+
8+
System.out.println("Массив целых чисел:");
9+
for (Integer element : integerArray.getArray()) {
10+
System.out.println(element);
11+
}
12+
13+
System.out.println("Элемент по индексу 2: " + integerArray.getElementByIndex(2));
14+
15+
String[] stringArray = {"apple", "banana", "cherry"};
16+
GenericArray<String> stringGenericArray = new GenericArray<>(stringArray);
17+
18+
System.out.println("\nМассив строк:");
19+
for (String element : stringGenericArray.getArray()) {
20+
System.out.println(element);
21+
}
22+
23+
System.out.println("Элемент по индексу 1: " + stringGenericArray.getElementByIndex(1));
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package ru.mirea.practice.s23k0169.t4;
2+
3+
import java.io.File;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
public abstract class DirectoryUtils {
8+
public static List<String> getDirectoryContents(String path) {
9+
File directory = new File(path);
10+
List<String> fileList = new ArrayList<>();
11+
12+
if (directory.isDirectory()) {
13+
for (File file : directory.listFiles()) {
14+
fileList.add(file.getName());
15+
}
16+
}
17+
18+
return fileList;
19+
}
20+
21+
public static void main(String[] args) {
22+
List<String> contents = getDirectoryContents("/Users/viktoriapermakova/Desktop/Java");
23+
contents.stream().limit(5).forEach(System.out::println);
24+
}
25+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ru.mirea.practice.s23k0169.t5;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
import java.util.Set;
6+
7+
public abstract class Main {
8+
public static void main(String[] args) {
9+
List<Integer> list = Solution.newArrayList(1, 2, 3, 4, 5);
10+
System.out.println("ArrayList: " + list);
11+
12+
Set<String> set = Solution.newHashSet("a", "b", "c");
13+
System.out.println("HashSet: " + set);
14+
15+
Map<String, Integer> map = Solution.newHashMap("key1", 100);
16+
System.out.println("HashMap: " + map);
17+
}
18+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ru.mirea.practice.s23k0169.t5;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashMap;
5+
import java.util.HashSet;
6+
import java.util.List;
7+
import java.util.Map;
8+
import java.util.Set;
9+
10+
public abstract class Solution {
11+
public static <T> List<T> newArrayList(T... elements) {
12+
List<T> list = new ArrayList<>();
13+
for (T element : elements) {
14+
list.add(element);
15+
}
16+
return list;
17+
}
18+
19+
public static <T> Set<T> newHashSet(T... elements) {
20+
Set<T> set = new HashSet<>();
21+
for (T element : elements) {
22+
set.add(element);
23+
}
24+
return set;
25+
}
26+
27+
public static <K, V> Map<K, V> newHashMap(K key, V value) {
28+
Map<K, V> map = new HashMap<>();
29+
map.put(key, value);
30+
return map;
31+
}
32+
}

students/23K0169/23K0169-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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>23K0169</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0169-p22</artifactId>
12+
<description>Массивы</description>
13+
</project>

0 commit comments

Comments
 (0)