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

Commit bdd7561

Browse files
authored
Merge pull request #690 from DNLdmitrylavrischev/lab1-32
Лабораторная 1-32
2 parents 4749714 + 1afc912 commit bdd7561

File tree

51 files changed

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

51 files changed

+2003
-0
lines changed

students/23K0355/23K0355-p20/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>23K0355</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0355-p20</artifactId>
12+
<description>Практика 20 Лаврищев </description>
13+
</project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package ru.mirea.practice.task1;
2+
3+
public class MyGenericClass<T, V, K> {
4+
5+
private T a;
6+
private V b;
7+
private K c;
8+
9+
public MyGenericClass(T a, V b, K c) {
10+
this.a = a;
11+
this.b = b;
12+
this.c = c;
13+
}
14+
15+
public T getA() {
16+
return a;
17+
}
18+
19+
public V getB() {
20+
return b;
21+
}
22+
23+
public K getC() {
24+
return c;
25+
}
26+
27+
public void printClassNames() {
28+
System.out.println("Тип первой переменной: " + a.getClass().getName());
29+
System.out.println("Тип второй переменной: " + b.getClass().getName());
30+
System.out.println("Тип третьей переменной: " + c.getClass().getName());
31+
}
32+
33+
public static void main(String[] args) {
34+
MyGenericClass<Integer, String, Double> obj = new MyGenericClass<>(10, "Привет", 3.14);
35+
System.out.println("Первая переменная: " + obj.getA());
36+
System.out.println("Вторая переменная: " + obj.getB());
37+
System.out.println("Третья переменная: " + obj.getC());
38+
obj.printClassNames();
39+
}
40+
}

students/23K0355/23K0355-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>23K0355</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0355-p21</artifactId>
12+
<description>Практика 21 Лаврищев </description>
13+
</project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package ru.mirea.practice.task1;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.Scanner;
6+
7+
public final class Main {
8+
9+
private Main() {}
10+
11+
public static <T> List<T> convertToList(T[] arr) {
12+
List<T> list = new ArrayList<>();
13+
for (T el : arr) {
14+
list.add(el);
15+
}
16+
return list;
17+
}
18+
19+
public static void main(String[] args) {
20+
try (Scanner sc = new Scanner(System.in)) {
21+
22+
System.out.println("Выберите тип массива для конвертации в список:");
23+
System.out.println("1. Массив строк");
24+
System.out.println("2. Массив чисел");
25+
System.out.print("Введите номер варианта (1 или 2): ");
26+
int ch = sc.nextInt();
27+
sc.nextLine();
28+
29+
if (ch == 1) {
30+
System.out.print("Введите количество строк: ");
31+
int n = sc.nextInt();
32+
sc.nextLine();
33+
String[] strArr = new String[n];
34+
35+
System.out.println("Введите строки:");
36+
for (int i = 0; i < n; i++) {
37+
strArr[i] = sc.nextLine();
38+
}
39+
40+
List<String> strList = convertToList(strArr);
41+
System.out.println("Список строк: " + strList);
42+
} else if (ch == 2) {
43+
System.out.print("Введите количество чисел: ");
44+
int n = sc.nextInt();
45+
Integer[] numArr = new Integer[n];
46+
47+
System.out.println("Введите числа:");
48+
for (int i = 0; i < n; i++) {
49+
numArr[i] = sc.nextInt();
50+
}
51+
52+
List<Integer> numList = convertToList(numArr);
53+
System.out.println("Список чисел: " + numList);
54+
} else {
55+
System.out.println("Неверный выбор!");
56+
}
57+
}
58+
}
59+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package ru.mirea.practice.task2;
2+
3+
import java.util.Scanner;
4+
5+
public class GenericArray<T> {
6+
7+
private T[] arr;
8+
9+
public GenericArray(int s) {
10+
arr = (T[]) new Object[s];
11+
}
12+
13+
public void set(int idx, T val) {
14+
if (idx >= 0 && idx < arr.length) {
15+
arr[idx] = val;
16+
} else {
17+
System.out.println("Index out of bounds");
18+
}
19+
}
20+
21+
public T get(int idx) {
22+
if (idx >= 0 && idx < arr.length) {
23+
return arr[idx];
24+
} else {
25+
System.out.println("Index out of bounds");
26+
return null;
27+
}
28+
}
29+
30+
public void printArray() {
31+
for (int i = 0; i < arr.length; i++) {
32+
System.out.println("Element at index " + i + ": " + arr[i]);
33+
}
34+
}
35+
36+
public static void main(String[] args) {
37+
try (Scanner sc = new Scanner(System.in)) {
38+
39+
System.out.println("Выберите тип массива для работы:");
40+
System.out.println("1. Массив строк");
41+
System.out.println("2. Массив целых чисел");
42+
System.out.println("3. Массив чисел с плавающей запятой");
43+
System.out.print("Введите номер варианта (1, 2 или 3): ");
44+
final int ch = sc.nextInt();
45+
sc.nextLine();
46+
47+
System.out.print("Введите размер массива: ");
48+
final int sz = sc.nextInt();
49+
sc.nextLine();
50+
51+
switch (ch) {
52+
case 1:
53+
GenericArray<String> strArr = new GenericArray<>(sz);
54+
System.out.println("Введите элементы массива строк:");
55+
for (int i = 0; i < sz; i++) {
56+
strArr.set(i, sc.nextLine());
57+
}
58+
strArr.printArray();
59+
break;
60+
61+
case 2:
62+
GenericArray<Integer> intArr = new GenericArray<>(sz);
63+
System.out.println("Введите элементы массива целых чисел:");
64+
for (int i = 0; i < sz; i++) {
65+
intArr.set(i, sc.nextInt());
66+
}
67+
intArr.printArray();
68+
break;
69+
70+
case 3:
71+
GenericArray<Double> dblArr = new GenericArray<>(sz);
72+
System.out.println("Введите элементы массива чисел с плавающей запятой:");
73+
for (int i = 0; i < sz; i++) {
74+
dblArr.set(i, sc.nextDouble());
75+
}
76+
dblArr.printArray();
77+
break;
78+
79+
default:
80+
System.out.println("Неверный выбор.");
81+
break;
82+
}
83+
84+
} catch (Exception e) {
85+
e.printStackTrace();
86+
}
87+
}
88+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package ru.mirea.practice.task3;
2+
3+
import java.util.Scanner;
4+
5+
public final class Main {
6+
7+
private Main() {
8+
}
9+
10+
public static void main(String[] args) {
11+
try (Scanner sc = new Scanner(System.in)) {
12+
13+
System.out.println("Выберите тип массива для работы:");
14+
System.out.println("1. Массив строк");
15+
System.out.println("2. Массив целых чисел");
16+
System.out.println("3. Массив чисел с плавающей запятой");
17+
System.out.print("Введите номер варианта (1, 2 или 3): ");
18+
final int ch = sc.nextInt();
19+
sc.nextLine();
20+
21+
System.out.print("Введите размер массива: ");
22+
final int sz = sc.nextInt();
23+
sc.nextLine();
24+
25+
switch (ch) {
26+
case 1:
27+
String[] sa = new String[sz];
28+
System.out.println("Введите элементы массива строк:");
29+
for (int i = 0; i < sz; i++) {
30+
sa[i] = sc.nextLine();
31+
}
32+
System.out.print("Введите индекс для получения элемента: ");
33+
int is = sc.nextInt();
34+
System.out.println("Элемент по индексу " + is + ": " + getElement(sa, is));
35+
break;
36+
37+
case 2:
38+
Integer[] ia = new Integer[sz];
39+
System.out.println("Введите элементы массива целых чисел:");
40+
for (int i = 0; i < sz; i++) {
41+
ia[i] = sc.nextInt();
42+
}
43+
System.out.print("Введите индекс для получения элемента: ");
44+
int ii = sc.nextInt();
45+
System.out.println("Элемент по индексу " + ii + ": " + getElement(ia, ii));
46+
break;
47+
48+
case 3:
49+
Double[] da = new Double[sz];
50+
System.out.println("Введите элементы массива чисел с плавающей запятой:");
51+
for (int i = 0; i < sz; i++) {
52+
da[i] = sc.nextDouble();
53+
}
54+
System.out.print("Введите индекс для получения элемента: ");
55+
int id = sc.nextInt();
56+
System.out.println("Элемент по индексу " + id + ": " + getElement(da, id));
57+
break;
58+
59+
default:
60+
System.out.println("Неверный выбор.");
61+
break;
62+
}
63+
64+
} catch (Exception e) {
65+
e.printStackTrace();
66+
}
67+
}
68+
69+
public static <T> T getElement(T[] arr, int idx) {
70+
if (idx >= 0 && idx < arr.length) {
71+
return arr[idx];
72+
} else {
73+
System.out.println("Индекс выходит за пределы массива.");
74+
return null;
75+
}
76+
}
77+
}
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>23K0355</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0355-p22.1</artifactId>
12+
<description>Практика№22 Лаврищев Д.Н.</description>
13+
</project>

0 commit comments

Comments
 (0)