mirror of
https://github.com/ASDjonok/OOP_IO-2x_2023.git
synced 2026-04-01 21:21:50 +03:00
Compare commits
23 Commits
ІО-25/18-М
...
ІО-25/01-А
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9eab1efbc2 | ||
|
|
a9dac38d8c | ||
|
|
77e8f72f79 | ||
|
|
5c1edd02c8 | ||
|
|
830f117858 | ||
|
|
dbe4b8119c | ||
|
|
7ce8251e6d | ||
|
|
29e63163a4 | ||
|
|
399941844f | ||
|
|
f385bff73d | ||
|
|
6d8171ad4c | ||
|
|
14c58d0cc4 | ||
|
|
afc13cf9f8 | ||
|
|
e910ee6e4d | ||
|
|
6ab6cc17db | ||
|
|
25173d66d1 | ||
|
|
41ad598b79 | ||
|
|
13e1a61ad9 | ||
|
|
f692ae7588 | ||
|
|
429bcc7b3d | ||
|
|
4b159fa22b | ||
|
|
2880b770f7 | ||
|
|
53a9d20438 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
||||
# Project exclude paths
|
||||
/out/
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
|
||||
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
9
.idea/OOP_IO-2x_2023.iml
generated
Normal file
9
.idea/OOP_IO-2x_2023.iml
generated
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
11
.idea/modules.xml
generated
Normal file
11
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/OOP_IO-2x_2023.iml" filepath="$PROJECT_DIR$/.idea/OOP_IO-2x_2023.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/lab1/lab1.iml" filepath="$PROJECT_DIR$/lab1/lab1.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/lab2/lab2.iml" filepath="$PROJECT_DIR$/lab2/lab2.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/lab3/lab3.iml" filepath="$PROJECT_DIR$/lab3/lab3.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
2
README.md
Normal file
2
README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# Laboratory OOP - IO-2x - 2023
|
||||
Antonenko Violetta
|
||||
8
lab1/FunctionCalculator/.idea/.gitignore
generated
vendored
Normal file
8
lab1/FunctionCalculator/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
1
lab1/FunctionCalculator/.idea/.name
generated
Normal file
1
lab1/FunctionCalculator/.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
||||
Main.java
|
||||
6
lab1/FunctionCalculator/.idea/misc.xml
generated
Normal file
6
lab1/FunctionCalculator/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
lab1/FunctionCalculator/.idea/modules.xml
generated
Normal file
8
lab1/FunctionCalculator/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/FunctionCalculator.iml" filepath="$PROJECT_DIR$/FunctionCalculator.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
51
lab1/FunctionCalculator/src/Main.java
Normal file
51
lab1/FunctionCalculator/src/Main.java
Normal file
@@ -0,0 +1,51 @@
|
||||
import java.util.Scanner;
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
//C2 = 2501 % 2 = 1, і операція O1 буде відніманням (-).
|
||||
//C3 = 2501 % 3 = 2
|
||||
//C5 = 2501 % 5 = 1, і операція O2 буде діленням (/).
|
||||
//C7 = 2501 % 7 = 4, тип індексів i та j буде char.
|
||||
double result = 0; // результат
|
||||
char i, j;
|
||||
char operation1 = '-';
|
||||
double constant = 2.0;
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.print("Введіть значення n: ");
|
||||
int n = scanner.nextInt();
|
||||
System.out.print("Введіть значення m: ");
|
||||
int m = scanner.nextInt();
|
||||
|
||||
// Обчислення значення функції S
|
||||
for (i = 'a'; i <= 'a' + n - 1; i++) {
|
||||
for (j = 'b'; j <= 'b' + m - 1; j++) {
|
||||
try {
|
||||
double value = (double) i / applyOperation(j, operation1, constant);
|
||||
result += value;
|
||||
} catch (ArithmeticException e) {
|
||||
System.out.println("Ділення на нуль: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
System.out.println("Виникла помилка: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Виведення результату
|
||||
System.out.println("Результат: " + result);
|
||||
}
|
||||
|
||||
// Метод, який застосовує операцію О1 до двох чисел
|
||||
public static double applyOperation(char j, char operation, double constant) throws Exception {
|
||||
switch (operation) {
|
||||
case '-':
|
||||
return (double) j - constant;
|
||||
case '/':
|
||||
if (constant == 0.0) {
|
||||
throw new ArithmeticException("C не може бути рівним нулю");
|
||||
} else {
|
||||
return (double) j / constant;
|
||||
}
|
||||
default:
|
||||
throw new Exception("Непідтримувана операція: " + operation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/FunctionCalculator/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
||||
BIN
lab1/lab1.pdf
Normal file
BIN
lab1/lab1.pdf
Normal file
Binary file not shown.
Binary file not shown.
@@ -1,21 +0,0 @@
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
float s = 0.0f, a = 2.0f, b = 1.0f, m = 6.0f, n = 4.0f;
|
||||
int c = 1;
|
||||
|
||||
for (float i = a; i <= m; i++) {
|
||||
// Перевірка ділення на 0.
|
||||
if (i == -1) {
|
||||
System.out.println("Помилка: ділення на нуль не можливе.");
|
||||
return;
|
||||
}
|
||||
for (float j = b; j <= n; j++) {
|
||||
s += (i + j) / (i + c);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("S = " + s);
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
8
lab2/Matrix/.idea/.gitignore
generated
vendored
Normal file
8
lab2/Matrix/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
1
lab2/Matrix/.idea/.name
generated
Normal file
1
lab2/Matrix/.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
||||
Main.java
|
||||
6
lab2/Matrix/.idea/misc.xml
generated
Normal file
6
lab2/Matrix/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
lab2/Matrix/.idea/modules.xml
generated
Normal file
8
lab2/Matrix/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Matrix.iml" filepath="$PROJECT_DIR$/Matrix.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
BIN
lab2/Matrix/out/production/Matrix/Main.class
Normal file
BIN
lab2/Matrix/out/production/Matrix/Main.class
Normal file
Binary file not shown.
58
lab2/Matrix/src/Main.java
Normal file
58
lab2/Matrix/src/Main.java
Normal file
@@ -0,0 +1,58 @@
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
byte[][] matrix = {{4, 7, 3}, {4, 7, 6}, {7, 10, 9}};
|
||||
|
||||
//C5 = 2501 mod 5 = 1, тому C = B^T (транспонування матриці)
|
||||
//C7 = 2501 mod 7 = 1, тому тип елементів матриці має бути byte
|
||||
//C11 = 2501 mod 11 = 10, тому треба знайти середнє значення елементів матриці
|
||||
|
||||
// Виконуємо дію з матрицею: транспонування матриці B
|
||||
byte[][] transposedMatrix = transposeMatrix(matrix);
|
||||
System.out.println("Transposed matrix: ");
|
||||
printMatrix(transposedMatrix);
|
||||
|
||||
// Виконуємо дію з матрицею C: знаходимо середнє значення елементів матриці
|
||||
double average = calculateAverage(transposedMatrix);
|
||||
System.out.println("Cереднє значення елементів матриці: " + average);
|
||||
}
|
||||
|
||||
// Метод для транспонування матриці
|
||||
private static byte[][] transposeMatrix(byte[][] matrix) {
|
||||
int rows = matrix.length;
|
||||
int columns = matrix[0].length;
|
||||
|
||||
byte[][] transposedMatrix = new byte[columns][rows];
|
||||
|
||||
for (int i = 0; i < rows; i++) {
|
||||
for (int j = 0; j < columns; j++) {
|
||||
transposedMatrix[j][i] = matrix[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
return transposedMatrix;
|
||||
}
|
||||
|
||||
// Метод для знаходження середнього значення елементів матриці
|
||||
private static double calculateAverage(byte[][] matrix) {
|
||||
int rows = matrix.length;
|
||||
int columns = matrix[0].length;
|
||||
|
||||
int sum = 0;
|
||||
for (int i = 0; i < rows; i++) {
|
||||
for (int j = 0; j < columns; j++) {
|
||||
sum += matrix[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
return (double) sum / (rows * columns);
|
||||
}
|
||||
|
||||
// Метод для виведення матриці на екран
|
||||
private static void printMatrix(byte[][] matrix) {
|
||||
for (byte[] row : matrix) {
|
||||
System.out.println(Arrays.toString(row));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/Matrix/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
||||
BIN
lab2/lab2.pdf
Normal file
BIN
lab2/lab2.pdf
Normal file
Binary file not shown.
Binary file not shown.
@@ -1,59 +0,0 @@
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// Створення матриць.
|
||||
char[][] a = {
|
||||
{12, 4, 8, 11},
|
||||
{16, 9, 3, 13},
|
||||
{7, 11, 16, 15}
|
||||
};
|
||||
char[][] b = {
|
||||
{15, 12, 4, 5},
|
||||
{19, 1, 3, 11},
|
||||
{2, 11, 6, 10}
|
||||
};
|
||||
|
||||
System.out.println("Матриця A: ");
|
||||
for (char[] i : a) {
|
||||
for (char j : i) {
|
||||
/* При виведенні елементів ми додаємо пробіли на кінці
|
||||
цілого числа (%-4d) задля легшого читання матриці.
|
||||
*/
|
||||
System.out.printf("%-4d", (int) j);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
System.out.println("\nМатриця B: ");
|
||||
for (char[] i : b) {
|
||||
for (char j : i) {
|
||||
System.out.printf("%-4d", (int) j);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
// Перевірка на те, чи є матриці однакових форм.
|
||||
if (a[0].length != b[0].length || a.length != b.length) {
|
||||
System.out.println("Матриці А і В мають різні форми.");
|
||||
} else {
|
||||
int[][] c = new int[a.length][a[0].length];
|
||||
float sum = 0;
|
||||
|
||||
System.out.println("\nМатриця С: ");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
for (int j = 0; j < a[i].length; j++) {
|
||||
|
||||
c[i][j] = (byte) a[i][j] ^ (byte) b[i][j];
|
||||
sum += c[i][j];
|
||||
System.out.printf("%-4d", c[i][j]);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
float average = sum / (c.length * c[0].length);
|
||||
System.out.printf("\nСереднє значення матриці С: %.3f", average);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
8
lab3/OperationsStrings/.idea/.gitignore
generated
vendored
Normal file
8
lab3/OperationsStrings/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
1
lab3/OperationsStrings/.idea/.name
generated
Normal file
1
lab3/OperationsStrings/.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
||||
Main.java
|
||||
6
lab3/OperationsStrings/.idea/misc.xml
generated
Normal file
6
lab3/OperationsStrings/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
lab3/OperationsStrings/.idea/modules.xml
generated
Normal file
8
lab3/OperationsStrings/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/OperationsStrings.iml" filepath="$PROJECT_DIR$/OperationsStrings.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
25
lab3/OperationsStrings/src/Main.java
Normal file
25
lab3/OperationsStrings/src/Main.java
Normal file
@@ -0,0 +1,25 @@
|
||||
import java.util.HashSet;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String inputText = "Who are you? What is your name? Where are you from?";
|
||||
int targetLength = 3;
|
||||
|
||||
try {
|
||||
HashSet<String> uniqueWords = new HashSet<String>();
|
||||
String[] sentences = inputText.split("[?]");
|
||||
for (String sentence : sentences) {
|
||||
String[] words = sentence.trim().split("\\s+");
|
||||
for (String word : words) {
|
||||
if (word.length() == targetLength) {
|
||||
uniqueWords.add(word.toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("Unique words of length " + targetLength + " in the input text are: " + uniqueWords);
|
||||
} catch (Exception e) {
|
||||
System.out.println("An error occurred: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/OperationsStrings/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
||||
BIN
lab3/lab3.pdf
Normal file
BIN
lab3/lab3.pdf
Normal file
Binary file not shown.
Binary file not shown.
@@ -1,54 +0,0 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
StringBuffer text = new StringBuffer(scanner.nextLine());
|
||||
String str_text = text.toString();
|
||||
// Заміна ? й ! на .
|
||||
str_text = str_text.replaceAll("[?!]", ".");
|
||||
// Очищення від спеціальних символів.
|
||||
str_text = str_text.replaceAll("\"", "");
|
||||
str_text = str_text.replaceAll("-", "");
|
||||
str_text = str_text.replaceAll("[,':;^*&%$#@]", "");
|
||||
// Створення масиву з речень.
|
||||
String[] spl_text = str_text.split("\\.");
|
||||
|
||||
// Перевірка на кількість речень.
|
||||
if (spl_text.length == 0 || spl_text.length == 1) {
|
||||
System.out.println("Не вдалося виконати дію з рядками (було введено одне речення або взагалі нічого)");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Слова першого речення, яких немає у жодному з наступних:");
|
||||
for (String st : spl_text[0].split(" ")) {
|
||||
int index = 0;
|
||||
for (int i = 1; i < spl_text.length; i++) {
|
||||
// Усунення кейсу з регістром, усунення пробілів.
|
||||
if (Arrays.asList(spl_text[i].toLowerCase().trim().split(" ")).contains(st.trim().toLowerCase())) {
|
||||
index = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Перевірка на те, чи було дане слово хоча б в одному реченні.
|
||||
if (index == 0) {
|
||||
System.out.println(st.trim().toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* [Input]
|
||||
"У молодості я взяв собі за правило не пити ні краплі спиртного до обіду. Тепер, коли я вже немолодий, я тримаюся правила не пити ні краплі спиртного до сніданку". - Вінстон Черчилль
|
||||
[Output]
|
||||
у
|
||||
молодості
|
||||
взяв
|
||||
собі
|
||||
за
|
||||
правило
|
||||
обіду
|
||||
*/
|
||||
Binary file not shown.
8
lab4/.idea/.gitignore
generated
vendored
Normal file
8
lab4/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
9
lab4/.idea/lab4.iml
generated
Normal file
9
lab4/.idea/lab4.iml
generated
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
8
lab4/.idea/modules.xml
generated
Normal file
8
lab4/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/lab4.iml" filepath="$PROJECT_DIR$/.idea/lab4.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
6
lab4/.idea/vcs.xml
generated
Normal file
6
lab4/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
8
lab4/EducationalInstitution/.idea/.gitignore
generated
vendored
Normal file
8
lab4/EducationalInstitution/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
6
lab4/EducationalInstitution/.idea/misc.xml
generated
Normal file
6
lab4/EducationalInstitution/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
lab4/EducationalInstitution/.idea/modules.xml
generated
Normal file
8
lab4/EducationalInstitution/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/EducationalInstitution.iml" filepath="$PROJECT_DIR$/EducationalInstitution.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
Binary file not shown.
0
lab4/EducationalInstitution/src/Main.java
Normal file
0
lab4/EducationalInstitution/src/Main.java
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,40 +0,0 @@
|
||||
package lab4;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// Створення об'єктів класу Student.
|
||||
Student First = new Student("Михайло", "Гордун", 21, "ІПСА", true);
|
||||
Student Second = new Student("Дмитро", "Шарій", 19, "ТЕФ", false);
|
||||
Student Third = new Student("Аліна", "Шарій", 18, "ЕФ", false);
|
||||
Student Fourth = new Student("Назар", "Лоленко", 17, "ФІОТ", true);
|
||||
Student Fifth = new Student("Олександра", "Зеленська", 18, "ФМВ", true);
|
||||
|
||||
// Створення масиву об'єктів класу Student.
|
||||
Student[] ObjArray = new Student[] {First, Second, Third, Fourth, Fifth};
|
||||
|
||||
// Сортування по алфавіту (прізвище ім'я).
|
||||
Arrays.sort(ObjArray, new Sorting.SortByAlphabet());
|
||||
System.out.println("\nСортування за алфавітом (зростання):");
|
||||
for (Student Student : ObjArray) {
|
||||
System.out.println(Student.lastName + " " + Student.firstName);
|
||||
}
|
||||
|
||||
/* Сортування по віці (спадання).
|
||||
Масив сортує масив по зростанню, але в циклі ітерація
|
||||
проходить навпаки, тим самим виводячи елементи з кінця
|
||||
до початку.
|
||||
*/
|
||||
Arrays.sort(ObjArray, new Sorting.SortByAge());
|
||||
System.out.println("\nСортування за віком (спадання):");
|
||||
for (int i = ObjArray.length-1; i >= 0; i--) {
|
||||
System.out.print(ObjArray[i].lastName + " ");
|
||||
System.out.print(ObjArray[i].firstName);
|
||||
System.out.println(", вік: " + ObjArray[i].age);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package lab4;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class Sorting {
|
||||
|
||||
// Непорушний клас, створений на основі абстратного класу Comparator.
|
||||
public static class SortByAlphabet implements Comparator<Student> {
|
||||
|
||||
/* Реалізація методу compare().
|
||||
Метод compare(Object o1, Object 02) є одним із абстрактних методів
|
||||
класу Comparator. Нам потрібно або зробити наш клас абстактним, або
|
||||
реалізувати даний метод. Якщо ж оголосити клас SortByAlphabet
|
||||
абстрактним, ми не зможемо створити на основі його об'єкт, тому
|
||||
вибір очевидний - реалізація методу.
|
||||
*/
|
||||
@Override
|
||||
public int compare(Student st1, Student st2) {
|
||||
/* Якщо в нас буде 2 однакових прізвища на порівняння, нам потрібно
|
||||
порівнювати імена аби сортування по алфавіту було правильним.
|
||||
*/
|
||||
if (st1.lastName.compareTo(st2.lastName) == 0) {
|
||||
return st1.firstName.compareTo(st2.firstName);
|
||||
} else {
|
||||
return st1.lastName.compareTo(st2.lastName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Непорушний клас, створений на основі абстратного класу Comparator.
|
||||
public static class SortByAge implements Comparator<Student> {
|
||||
|
||||
// Аналогічно тут, реалізуємо метод compare().
|
||||
@Override
|
||||
public int compare(Student st1, Student st2) {
|
||||
/* Метод compareTo() приймає лише дані типу String, тому
|
||||
ми перетворюємо вік з int в String. Звісно ж це може привести
|
||||
до неточності. Числа будуть порівнюватись спочатку по перших
|
||||
цифрах, потім по других і тд. Якщо в нас буде, наприклад вік
|
||||
107 і 18 на порівнянні, прогрма порахує, що 18 > 107 по
|
||||
порядку. Тут цим знехтується, адже я сумніваюсь що існують
|
||||
студенти яким >100 років.
|
||||
*/
|
||||
String age1 = Integer.toString(st1.age);
|
||||
String age2 = Integer.toString(st2.age);
|
||||
return age1.compareTo(age2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package lab4;
|
||||
|
||||
public class Student {
|
||||
|
||||
// Створення полів класу.
|
||||
public String firstName;
|
||||
public String lastName;
|
||||
public int age;
|
||||
private String faculty;
|
||||
private boolean hasStipend;
|
||||
|
||||
// Конструктор класу.
|
||||
public Student(String fn, String ln, int age, String fac, boolean wealth) {
|
||||
setValues(fn, ln, age, fac, wealth);
|
||||
getValues();
|
||||
}
|
||||
|
||||
/* Метод, який нічого не повертає.
|
||||
Визначає поля класу.
|
||||
*/
|
||||
private void setValues(String fn, String ln, int age, String fac, boolean wealth) {
|
||||
this.firstName = fn;
|
||||
this.lastName = ln;
|
||||
this.age = age;
|
||||
this.faculty = fac;
|
||||
this.hasStipend = wealth;
|
||||
}
|
||||
|
||||
/* Метод, який нічого не повертає.
|
||||
Виводить значення полів.
|
||||
*/
|
||||
private void getValues() {
|
||||
System.out.println("Прізвище та ім'я: " + this.lastName + " " + this.firstName);
|
||||
System.out.println("Вік: " + this.age);
|
||||
System.out.println("Факультет: " + this.faculty);
|
||||
System.out.print("Наявність стипендії: ");
|
||||
if (this.hasStipend)
|
||||
System.out.println("є");
|
||||
else
|
||||
System.out.println("немає");
|
||||
System.out.println("~".repeat(40));
|
||||
}
|
||||
|
||||
}
|
||||
8
lab4/untitled/.idea/.gitignore
generated
vendored
Normal file
8
lab4/untitled/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
6
lab4/untitled/.idea/misc.xml
generated
Normal file
6
lab4/untitled/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
lab4/untitled/.idea/modules.xml
generated
Normal file
8
lab4/untitled/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/untitled.iml" filepath="$PROJECT_DIR$/untitled.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
BIN
lab4/untitled/out/production/untitled/Main.class
Normal file
BIN
lab4/untitled/out/production/untitled/Main.class
Normal file
Binary file not shown.
BIN
lab4/untitled/out/production/untitled/SeaShip.class
Normal file
BIN
lab4/untitled/out/production/untitled/SeaShip.class
Normal file
Binary file not shown.
56
lab4/untitled/src/Main.java
Normal file
56
lab4/untitled/src/Main.java
Normal file
@@ -0,0 +1,56 @@
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
List<SeaShip> ships = createList();
|
||||
|
||||
printList(ships);
|
||||
|
||||
ships = sortList(ships);
|
||||
|
||||
System.out.println("==============================");
|
||||
|
||||
printList(ships);
|
||||
}
|
||||
|
||||
private static ArrayList<SeaShip> createList() {
|
||||
ArrayList<SeaShip> ships = new ArrayList<>();
|
||||
Random random = new Random();
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
ships.add(new SeaShip("name" + (i + 1), "class" + (i + 1), "type" + (i + 1),
|
||||
random.nextInt(10000) + 1000, random.nextDouble() * 100 + 20,
|
||||
random.nextInt(10000) + 1000, random.nextDouble() * 100));
|
||||
|
||||
// ships.add(new SeaShip("nameA", "classA", "typeA",
|
||||
// random.nextInt(10000) + 1000, 100d,
|
||||
// random.nextInt(10000) + 1000, 120d));
|
||||
// ships.add(new SeaShip("nameA", "classA", "typeA",
|
||||
// random.nextInt(10000) + 1000, 100d,
|
||||
// random.nextInt(10000) + 1000, 130d));
|
||||
// ships.add(new SeaShip("nameA", "classA", "typeA",
|
||||
// random.nextInt(10000) + 1000, 100d,
|
||||
// random.nextInt(10000) + 1000, 140d));
|
||||
// ships.add(new SeaShip("nameA", "classA", "typeA",
|
||||
// random.nextInt(10000) + 1000, 120d,
|
||||
// random.nextInt(10000) + 1000, 120d));
|
||||
// ships.add(new SeaShip("nameA", "classA", "typeA",
|
||||
// random.nextInt(10000) + 1000, 120d,
|
||||
// random.nextInt(10000) + 1000, 100d));
|
||||
|
||||
return ships;
|
||||
}
|
||||
|
||||
private static List<SeaShip> sortList(List<SeaShip> list) {
|
||||
Comparator<SeaShip> comparator = Comparator.comparing(SeaShip::getLength).reversed()
|
||||
.thenComparing(SeaShip::getMaxSpeed);
|
||||
|
||||
list.sort(comparator);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static void printList(List<SeaShip> list) {
|
||||
list.forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
86
lab4/untitled/src/SeaShip.java
Normal file
86
lab4/untitled/src/SeaShip.java
Normal file
@@ -0,0 +1,86 @@
|
||||
|
||||
public class SeaShip {
|
||||
private String name;
|
||||
private String shipClass;
|
||||
private String type;
|
||||
private Integer weight;
|
||||
private Double length;
|
||||
private Integer power;
|
||||
private Double maxSpeed;
|
||||
|
||||
public SeaShip(String name, String shipClass, String type,
|
||||
Integer weight, Double length, Integer power, Double maxSpeed) {
|
||||
this.name = name;
|
||||
this.shipClass = shipClass;
|
||||
this.type = type;
|
||||
this.weight = weight;
|
||||
this.length = length;
|
||||
this.power = power;
|
||||
this.maxSpeed = maxSpeed;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getShipClass() {
|
||||
return shipClass;
|
||||
}
|
||||
|
||||
public void setShipClass(String shipClass) {
|
||||
this.shipClass = shipClass;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Integer getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(Integer weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public Double getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(Double length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public Integer getPower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
public void setPower(Integer power) {
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
public Double getMaxSpeed() {
|
||||
return maxSpeed;
|
||||
}
|
||||
|
||||
public void setMaxSpeed(Double maxSpeed) {
|
||||
this.maxSpeed = maxSpeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Sea ship '" + name + "', class: " + shipClass + ", type: " + type + ".\n" +
|
||||
"Weight: " + weight + "\n" +
|
||||
"Length: " + length + "\n" +
|
||||
"Engine power: " + power + "\n" +
|
||||
"Max speed: " + maxSpeed + "\n";
|
||||
}
|
||||
}
|
||||
11
lab4/untitled/untitled.iml
Normal file
11
lab4/untitled/untitled.iml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Binary file not shown.
BIN
lab5/lab5.pdf
Normal file
BIN
lab5/lab5.pdf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +0,0 @@
|
||||
package lab5;
|
||||
|
||||
public record Letter(char value) {
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package lab5;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String inputText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam tempor dictum velit, vitae sollicitudin mauris facilisis et. Praesent mi odio, pretium eget sem ac, ultricies eleifend elit. Maecenas vulputate efficitur risus, a ornare lorem sollicitudin vitae. Pellentesque rhoncus posuere risus eu placerat. Maecenas luctus felis ac interdum sodales. Quisque nec est lectus.";
|
||||
|
||||
// Створений Text об'єкт
|
||||
Text text = new Text(inputText);
|
||||
|
||||
// Пошук у першому реченні слів, яких немає в наступних реченнях
|
||||
List<String> result = findUniqueWords(text);
|
||||
System.out.println("Unique words in the first sentence: " + result);
|
||||
}
|
||||
|
||||
public static List<String> findUniqueWords(Text text) {
|
||||
if (text.getSentences().isEmpty()) {
|
||||
throw new IllegalArgumentException("Text must contain at least one sentence.");
|
||||
}
|
||||
|
||||
Sentence firstSentence = text.getSentences().get(0);
|
||||
List<String> wordsInFirstSentence = firstSentence.getStringWords();
|
||||
|
||||
Set<String> uniqueWords = new HashSet<>(wordsInFirstSentence);
|
||||
|
||||
for (int i = 1; i < text.getSentences().size(); i++) {
|
||||
Sentence sentence = text.getSentences().get(i);
|
||||
List<String> wordsInCurrentSentence = sentence.getStringWords();
|
||||
|
||||
wordsInCurrentSentence.forEach(uniqueWords::remove);
|
||||
}
|
||||
|
||||
return new ArrayList<>(uniqueWords);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package lab5;
|
||||
|
||||
public record Punctuation(char value) {
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package lab5;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Sentence {
|
||||
private final List<Object> wordsAndPunctuations;
|
||||
|
||||
public Sentence(String stringSentence) {
|
||||
List<Object> wordsAndPunctuations = new ArrayList<>();
|
||||
StringBuilder word = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < stringSentence.length(); i++) {
|
||||
char ch = stringSentence.charAt(i);
|
||||
|
||||
if (Character.isLetterOrDigit(ch)) {
|
||||
word.append(ch);
|
||||
} else if (Character.isWhitespace(ch)) {
|
||||
if (word.length() > 0) {
|
||||
wordsAndPunctuations.add(new Word(word.toString()));
|
||||
word.setLength(0);
|
||||
}
|
||||
} else if (String.valueOf(ch).matches(".*\\p{Punct}.*")) {
|
||||
if (word.length() > 0) {
|
||||
wordsAndPunctuations.add(new Word(word.toString()));
|
||||
word.setLength(0);
|
||||
}
|
||||
wordsAndPunctuations.add(new Punctuation(ch));
|
||||
}
|
||||
}
|
||||
|
||||
if (word.length() > 0) {
|
||||
wordsAndPunctuations.add(new Word(word.toString()));
|
||||
}
|
||||
|
||||
this.wordsAndPunctuations = wordsAndPunctuations;
|
||||
}
|
||||
|
||||
public List<Object> getWordsAndPunctuations() {
|
||||
return wordsAndPunctuations;
|
||||
}
|
||||
|
||||
|
||||
public List<Word> extractWords() {
|
||||
List<Word> words = new ArrayList<>();
|
||||
for (Object element : getWordsAndPunctuations()) {
|
||||
if (element instanceof Word) {
|
||||
words.add((Word) element);
|
||||
}
|
||||
}
|
||||
return words;
|
||||
}
|
||||
|
||||
public List<String> getStringWords() {
|
||||
List<String> wordStrings = new ArrayList<>();
|
||||
for (Word word : extractWords()) {
|
||||
wordStrings.add(word.getStringWord());
|
||||
}
|
||||
return wordStrings;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package lab5;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Text {
|
||||
private final List<Sentence> sentences;
|
||||
|
||||
public Text(String stringText) {
|
||||
this.sentences = new ArrayList<>();
|
||||
String[] splitText = stringText.split("(?<=[!.?])\\s*");
|
||||
for (String sentence : splitText) {
|
||||
getSentences().add(new Sentence(sentence));
|
||||
}
|
||||
}
|
||||
|
||||
public List<Sentence> getSentences() {
|
||||
return sentences;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package lab5;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Word {
|
||||
private final String stringWord;
|
||||
private final List<Letter> letters;
|
||||
|
||||
public Word(String stringWord) {
|
||||
List<Letter> letters = new ArrayList<>();
|
||||
char[] chars = stringWord.toCharArray();
|
||||
for (char c : chars) {
|
||||
letters.add(new Letter(c));
|
||||
}
|
||||
this.letters = letters;
|
||||
this.stringWord = stringWord;
|
||||
}
|
||||
|
||||
public List<Letter> getLetters() {
|
||||
return letters;
|
||||
}
|
||||
|
||||
public String getStringWord() {
|
||||
return stringWord;
|
||||
}
|
||||
|
||||
}
|
||||
8
lab5/untitled/.idea/.gitignore
generated
vendored
Normal file
8
lab5/untitled/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
6
lab5/untitled/.idea/misc.xml
generated
Normal file
6
lab5/untitled/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
lab5/untitled/.idea/modules.xml
generated
Normal file
8
lab5/untitled/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/untitled.iml" filepath="$PROJECT_DIR$/untitled.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
BIN
lab5/untitled/out/production/untitled/Letter.class
Normal file
BIN
lab5/untitled/out/production/untitled/Letter.class
Normal file
Binary file not shown.
BIN
lab5/untitled/out/production/untitled/Main.class
Normal file
BIN
lab5/untitled/out/production/untitled/Main.class
Normal file
Binary file not shown.
BIN
lab5/untitled/out/production/untitled/Sentence.class
Normal file
BIN
lab5/untitled/out/production/untitled/Sentence.class
Normal file
Binary file not shown.
BIN
lab5/untitled/out/production/untitled/Text.class
Normal file
BIN
lab5/untitled/out/production/untitled/Text.class
Normal file
Binary file not shown.
BIN
lab5/untitled/out/production/untitled/TextProcessor.class
Normal file
BIN
lab5/untitled/out/production/untitled/TextProcessor.class
Normal file
Binary file not shown.
BIN
lab5/untitled/out/production/untitled/Word.class
Normal file
BIN
lab5/untitled/out/production/untitled/Word.class
Normal file
Binary file not shown.
166
lab5/untitled/src/Main.java
Normal file
166
lab5/untitled/src/Main.java
Normal file
@@ -0,0 +1,166 @@
|
||||
import java.util.HashSet;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String inputText = "Раз два три, літо прийди! По ООП сто балів захвати. ім'я запише без апострофу, ех"; //вход даних, текст
|
||||
int targetLength = 3; //змінна, кількість літер в слові
|
||||
|
||||
try {
|
||||
TextProcessor textProcessor = new TextProcessor();
|
||||
HashSet<Word> uniqueWords = textProcessor.findUniqueWordsWithLength(inputText, targetLength);
|
||||
System.out.println("Unique words of length " + targetLength + " in the input text are: " + uniqueWords);// вивод повідомлення, що містить довжину та унікальні слова змінної
|
||||
} catch (Exception e) {
|
||||
System.out.println("An error occurred: " + e.getMessage());//вивиод помилки
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Letter {
|
||||
private char value;
|
||||
|
||||
public Letter(char value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public char getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(char value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
class Word {
|
||||
private Letter[] letters;
|
||||
|
||||
public Word(Letter[] letters) {
|
||||
this.letters = letters;
|
||||
}
|
||||
|
||||
public Letter[] getLetters() {
|
||||
return letters;
|
||||
}
|
||||
|
||||
public void setLetters(Letter[] letters) {
|
||||
this.letters = letters;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return letters.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Letter letter : letters) {
|
||||
sb.append(letter.getValue());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Word other = (Word) obj;
|
||||
return this.toString().equals(other.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.toString().hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
class Sentence {
|
||||
private Word[] words;
|
||||
private String punctuation;
|
||||
|
||||
public Sentence(Word[] words, String punctuation) {
|
||||
this.words = words;
|
||||
this.punctuation = punctuation;
|
||||
}
|
||||
|
||||
public Word[] getWords() {
|
||||
return words;
|
||||
}
|
||||
|
||||
public void setWords(Word[] words) {
|
||||
this.words = words;
|
||||
}
|
||||
|
||||
public String getPunctuation() {
|
||||
return punctuation;
|
||||
}
|
||||
|
||||
public void setPunctuation(String punctuation) {
|
||||
this.punctuation = punctuation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Word word : words) {
|
||||
sb.append(word.toString()).append(" ");
|
||||
}
|
||||
sb.append(punctuation);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class Text {
|
||||
private Sentence[] sentences;
|
||||
|
||||
public Text(Sentence[] sentences) {
|
||||
this.sentences = sentences;
|
||||
}
|
||||
|
||||
public Sentence[] getSentences() {
|
||||
return sentences;
|
||||
}
|
||||
|
||||
public void setSentences(Sentence[] sentences) {
|
||||
this.sentences = sentences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Sentence sentence : sentences) {
|
||||
sb.append(sentence.toString());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class TextProcessor {
|
||||
public HashSet<Word> findUniqueWordsWithLength(String inputText, int targetLength) {
|
||||
HashSet<Word> uniqueWords = new HashSet<>();
|
||||
String[] sentenceStrings = inputText.split("[?]");
|
||||
for (String sentenceString : sentenceStrings) {
|
||||
String[] wordStrings = sentenceString.trim().split("\\s+");
|
||||
for (String wordString : wordStrings) {
|
||||
wordString = wordString.replaceAll("[\\t\\s]+", " "); // Заміна послідовності табуляцій та пробілів одним пробілом
|
||||
wordString = wordString.replaceAll("[^\\p{L}\\s]", ""); // Вилучення розділових знаків
|
||||
wordString = wordString.toLowerCase(); // Перетворення на нижній регістр
|
||||
wordString = wordString.replace("’", ""); // Вилучення апострофів
|
||||
|
||||
if (wordString.length() == targetLength) {
|
||||
Letter[] letters = new Letter[wordString.length()];
|
||||
for (int i = 0; i < wordString.length(); i++) {
|
||||
letters[i] = new Letter(wordString.charAt(i));
|
||||
}
|
||||
Word word = new Word(letters);
|
||||
uniqueWords.add(word);
|
||||
}
|
||||
}
|
||||
}
|
||||
return uniqueWords;
|
||||
}
|
||||
}
|
||||
11
lab5/untitled/untitled.iml
Normal file
11
lab5/untitled/untitled.iml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
BIN
lab6/lab6.pdf
Normal file
BIN
lab6/lab6.pdf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user