Compare commits

..

38 Commits

Author SHA1 Message Date
a8cbadbe7d Added a Kotlin variation. 2023-05-07 23:15:50 +03:00
64c9e43742 Added a Kotlin variation. 2023-05-07 23:15:28 +03:00
5ca9ab6c17 Added a Kotlin variation. 2023-05-07 23:14:50 +03:00
a97f742be2 Added a Kotlin variation. 2023-05-07 23:14:24 +03:00
2494bea36c Camel case. 2023-05-07 22:20:31 +03:00
ca2b85ef9e . 2023-05-07 17:09:03 +03:00
77f96fafa6 Working model of Lab 3. 2023-05-07 17:07:56 +03:00
084f131c90 . 2023-05-07 16:46:18 +03:00
197426e266 Initial lab 3. 2023-05-07 15:19:23 +03:00
661c3641a1 Naming changes. 2023-05-07 15:19:06 +03:00
fc5704dd15 Cargo.toml added release profile. 2023-05-07 14:08:43 +03:00
45ef70b268 Finished lab_1 in Rust. 2023-05-07 09:26:25 +03:00
fe97b8dcde . 2023-05-06 23:56:34 +03:00
5c8d2bb8a1 . 2023-05-06 23:55:52 +03:00
6b6076f56c Merge branch 'ІО-23/30-Швед-Андрій-Дмитрович' of https://github.com/ASDjonok/OOP_IO-2x_2023 into ІО-23/30-Швед-Андрій-Дмитрович 2023-05-06 23:50:25 +03:00
9b08eb0dfc . 2023-05-06 23:50:22 +03:00
Rhinemann
9cce8b222e Delete Rust/lab_1/target directory 2023-05-06 23:47:52 +03:00
74209977bc . 2023-05-06 23:44:34 +03:00
83b275cefd . 2023-05-06 23:18:57 +03:00
af7af4d6f2 . 2023-05-06 23:09:06 +03:00
a4a3e09735 Lab 1. 2023-05-03 10:40:04 +03:00
acc2d533cb modified: Java/Lab 2/Lab_2.java 2023-05-03 10:39:06 +03:00
8013099c36 All sorts of corrections. 2023-05-03 10:32:23 +03:00
8100129706 Ceanup. 2023-05-02 11:42:37 +03:00
83d98b2982 Merge branch 'ІО-23/30-Швед-Андрій-Дмитрович' of https://github.com/ASDjonok/OOP_IO-2x_2023 into ІО-23/30-Швед-Андрій-Дмитрович 2023-05-02 11:40:28 +03:00
4af0ab5655 . 2023-05-02 11:38:55 +03:00
Rhinemann
07e9fbdc88 Delete Lab_2.class 2023-05-02 11:35:28 +03:00
Rhinemann
41aaaf4623 Delete Lab_1.class 2023-05-02 11:35:16 +03:00
99e9428dba Moved folders. 2023-05-02 11:34:34 +03:00
fe36219746 Update Lab 1. 2023-05-02 09:58:31 +03:00
896fc1f4d4 Minor cleanup 2023-04-26 14:37:46 +03:00
7fa667cb2d Changes 2023-04-26 14:34:13 +03:00
74a44852af Add Lab 2 2023-03-23 09:10:55 +02:00
Rhinemann
75112d90c2 Delete OOP_IO-2x_2023.iml 2023-03-23 08:59:27 +02:00
Rhinemann
e21575fa93 Delete .gitignore 2023-03-23 08:59:19 +02:00
Rhinemann
cf3d055f64 Delete src directory 2023-03-23 08:57:30 +02:00
Rhinemann
bdf5611f46 Delete .idea directory 2023-03-23 08:57:03 +02:00
Rhinemann
80de92fa1e Lab 1 commit 2023-03-22 17:02:31 +02:00
87 changed files with 290 additions and 945 deletions

6
.gitignore vendored
View File

@@ -1,4 +1,2 @@
# Project exclude paths Rust/lab_1/target
/out/ Rust/lab_2/target
# Auto detect text files and perform LF normalization
* text=auto

8
.idea/.gitignore generated vendored
View File

@@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -1,9 +0,0 @@
<?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
View File

@@ -1,6 +0,0 @@
<?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
View File

@@ -1,11 +0,0 @@
<?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
View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

31
Java/lab_1/lab_1.java Normal file
View File

@@ -0,0 +1,31 @@
import java.util.Scanner;
public class lab_1 {
public static int protectedInput(String variableToRead, Scanner input) {
do {
try {
System.out.printf("Enter %s: ", variableToRead);
return input.nextInt();
} catch (Exception e) {
System.out.printf("%s must be an integer.\n", variableToRead.toUpperCase());
input.nextLine();
}
} while (true);
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
final int n = protectedInput("n", input);
final int m = protectedInput("m", input);
final int a = protectedInput("a", input);
final int b = protectedInput("b", input);
input.close();
final float s = ((float) (b + m) / 2) * (m - b + 1) * (n - a + 1);
System.out.println("S = " + s);
}
}

21
Java/lab_1/lab_1.kt Normal file
View File

@@ -0,0 +1,21 @@
fun protectedInput(variableName: String): Int {
do {
try {
print("Enter $variableName: ")
return readln().toInt()
} catch (e: Exception) {
println("${variableName.uppercase()} must be an integer!")
}
} while (true)
}
fun main() {
val n: Int = protectedInput("n")
val m: Int = protectedInput("m")
val a: Int = protectedInput("a")
val b: Int = protectedInput("b")
val s: Float = (b + m).toFloat() / 2 * (m - b + 1) * (n - a + 1)
println("S = $s")
}

106
Java/lab_2/lab_2.java Normal file
View File

@@ -0,0 +1,106 @@
import java.util.Scanner;
public class lab_2 {
public static short protectedInput(String inputPrompt, String errorMessage, Scanner input) {
short read_variable;
do {
try {
System.out.println();
System.out.print(inputPrompt);
read_variable = input.nextShort();
break;
} catch (Exception e) {
System.out.println(errorMessage);
input.nextLine();
}
} while (true);
return read_variable;
}
public static String format(int number) {
int width = String.valueOf(number).length() + 1;
String format = "|%" + width + "d ";
return format;
}
public static double average(short[] row) {
short sum = 0;
for (short element : row) {
sum += element;
}
double result = sum / row.length;
return result;
}
public static void main(String[] args) {
short a, rows = 0, columns = 0;
String format;
Scanner input = new Scanner(System.in);
a = protectedInput("Input a constant to multipy a matrix by: ",
"A constant must be a short-data type integer, try again.", input);
System.out.println();
System.out.println("Input size of the matrix.");
do {
rows = protectedInput("Rows: ",
"A number of rows must be a short-data type integer, try again.", input);
} while (rows <= 0);
do {
columns = protectedInput("Columns: ",
"A number of columns must be a short-data type integer, try again.", input);
} while (columns <= 0);
input.close();
short[][] matrix_B = new short[rows][columns];
System.out.println();
System.out.println("Matrix B:");
format = format(rows * columns);
for (short i = 0; i < rows; i++) {
for (short j = 0; j < columns; j++) {
matrix_B[i][j] = (short) ((i + 1) * (j + 1));
System.out.printf(format, matrix_B[i][j]);
}
System.out.println("|");
}
System.out.println();
System.out.println("Matrix a×B:");
format = format(rows * columns * a);
for (short i = 0; i < matrix_B.length; i++) {
for (short j = 0; j < matrix_B[i].length; j++) {
matrix_B[i][j] *= (short) (a);
System.out.printf(format, matrix_B[i][j]);
}
System.out.println("|");
}
System.out.println();
System.out.println("Averages of each row:");
for (short[] row : matrix_B) {
System.out.println(average(row));
}
}
}

58
Java/lab_3/lab_3.java Normal file
View File

@@ -0,0 +1,58 @@
package OOP.Java.lab_3;
public class lab_3 {
static int maxStrLength;
static String result;
public static void cSubUtil(StringBuilder stringbuilder, int leftBoundary, int rightBoundary) {
String string = stringbuilder.toString().toLowerCase().replaceAll("[^a-z]","");
// check if the indices lie in the range of string
// and also if it is palindrome
while (leftBoundary >= 0 && rightBoundary < string.length() && string.toLowerCase().charAt(leftBoundary) == string.toLowerCase().charAt(rightBoundary)) {
// expand the boundary
leftBoundary--;
rightBoundary++;
}
// if it's length is greater than maxLength update
// maxLength and res
if (rightBoundary - leftBoundary - 1 >= maxStrLength) {
result = string.substring(leftBoundary + 1, rightBoundary);
maxStrLength = rightBoundary - leftBoundary - 1;
}
return;
}
public static int longestPalSubstr(StringBuilder string)
{
result = "";
maxStrLength = 1;
// for every index in the string check palindromes
// starting from that index
for (int i = 0; i < string.length(); i++) {
// check for odd length palindromes
cSubUtil(string, i, i);
// check for even length palindromes
cSubUtil(string, i, i + 1);
}
System.out.println("Longest palindrome substring is: " + compareStrings(string));
return compareStrings(string).length();
}
public static String compareStrings(StringBuilder builder) {
for (int leftBoundary = 0; leftBoundary <= builder.length(); leftBoundary++) {
for (int rightBoundary = builder.length(); leftBoundary >= 0; rightBoundary--) {
if (result.equals(builder.substring(leftBoundary, rightBoundary).toString().toLowerCase().replaceAll("[^a-z]",""))) {
return builder.substring(leftBoundary, rightBoundary).toString();
}
}
}
return "";
}
public static void main(String[] args) {
StringBuilder stringToDetect = new StringBuilder("Eva, can I see bees in a cave?");
System.out.println("Initial string: " + stringToDetect.toString());
System.out.println("Length is: " + longestPalSubstr(stringToDetect));
}
}

View File

@@ -1,2 +0,0 @@
# Laboratory OOP - IO-2x - 2023
Antonenko Violetta

16
Rust/lab_1/Cargo.lock generated Normal file
View File

@@ -0,0 +1,16 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "lab_1"
version = "0.1.0"
dependencies = [
"text_io",
]
[[package]]
name = "text_io"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5f0c8eb2ad70c12a6a69508f499b3051c924f4b1cfeae85bfad96e6bc5bba46"

16
Rust/lab_1/Cargo.toml Normal file
View File

@@ -0,0 +1,16 @@
[package]
name = "lab_1"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.release]
opt-level = 'z' # Optimize for size
lto = true # Enable link-time optimization
codegen-units = 1 # Reduce number of codegen units to increase optimizations
panic = 'abort' # Abort on panic
strip = true # Strip symbols from binary*
[dependencies]
text_io = "0.1.12"

22
Rust/lab_1/src/main.rs Normal file
View File

@@ -0,0 +1,22 @@
fn protected_read(variable_name: &str) -> i32 {
use text_io::try_read;
loop {
print!("Enter {}: ", variable_name);
let read_result: Result<i32, _> = try_read!();
match read_result {
Ok(read_integer) => return read_integer,
Err(_e) => println!("{} must be an integer!", variable_name.to_uppercase()),
}
}
}
fn main() {
let n: i32 = protected_read("n");
let m: i32 = protected_read("m");
let a: i32 = protected_read("a");
let b: i32 = protected_read("b");
let s: f32 = ((b + m) as f32 / 2f32) * ((m - b + 1) * (n - a + 1)) as f32;
println!("S = {}", s);
}

7
Rust/lab_2/Cargo.lock generated Normal file
View File

@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "lab_2"
version = "0.1.0"

8
Rust/lab_2/Cargo.toml Normal file
View File

@@ -0,0 +1,8 @@
[package]
name = "lab_2"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

3
Rust/lab_2/src/main.rs Normal file
View File

@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

View File

@@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -1 +0,0 @@
Main.java

View File

@@ -1,6 +0,0 @@
<?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>

View File

@@ -1,8 +0,0 @@
<?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>

View File

@@ -1,11 +0,0 @@
<?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>

View File

@@ -1,51 +0,0 @@
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);
}
}
}

View File

@@ -1,11 +0,0 @@
<?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$/FunctionCalculator/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

Binary file not shown.

8
lab2/Matrix/.idea/.gitignore generated vendored
View File

@@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -1 +0,0 @@
Main.java

View File

@@ -1,6 +0,0 @@
<?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>

View File

@@ -1,8 +0,0 @@
<?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>

View File

@@ -1,11 +0,0 @@
<?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>

View File

@@ -1,58 +0,0 @@
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));
}
}
}

View File

@@ -1,11 +0,0 @@
<?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$/Matrix/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

Binary file not shown.

View File

@@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -1 +0,0 @@
Main.java

View File

@@ -1,6 +0,0 @@
<?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>

View File

@@ -1,8 +0,0 @@
<?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>

View File

@@ -1,11 +0,0 @@
<?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>

View File

@@ -1,25 +0,0 @@
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());
}
}
}

View File

@@ -1,11 +0,0 @@
<?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$/OperationsStrings/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

Binary file not shown.

8
lab4/.idea/.gitignore generated vendored
View File

@@ -1,8 +0,0 @@
# 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
View File

@@ -1,9 +0,0 @@
<?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>

View File

@@ -1,8 +0,0 @@
<?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
View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -1,6 +0,0 @@
<?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>

View File

@@ -1,8 +0,0 @@
<?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>

View File

@@ -1,11 +0,0 @@
<?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>

8
lab4/untitled/.idea/.gitignore generated vendored
View File

@@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -1,6 +0,0 @@
<?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>

View File

@@ -1,8 +0,0 @@
<?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>

View File

@@ -1,56 +0,0 @@
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);
}
}

View File

@@ -1,86 +0,0 @@
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";
}
}

View File

@@ -1,11 +0,0 @@
<?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.

8
lab5/untitled/.idea/.gitignore generated vendored
View File

@@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -1,6 +0,0 @@
<?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>

View File

@@ -1,8 +0,0 @@
<?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>

View File

@@ -1,166 +0,0 @@
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;
}
}

View File

@@ -1,11 +0,0 @@
<?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.

8
lab6/untitled/.idea/.gitignore generated vendored
View File

@@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -1,6 +0,0 @@
<?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>

View File

@@ -1,8 +0,0 @@
<?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>

View File

@@ -1,159 +0,0 @@
import java.util.Arrays;
import java.util.Comparator;
/**
* Клас, що описує базовий рухомий склад залізничного транспорту.
*/
class RollingStock {
private int number;
public RollingStock(int number) {
this.number = number;
}
public int getNumber() {
return number;
}
}
/**
* Клас, що описує пасажирський вагон.
*/
class PassengerCarriage extends RollingStock {
private int passengerCount;
private int comfortLevel;
public PassengerCarriage(int number, int passengerCount, int comfortLevel) {
super(number);
this.passengerCount = passengerCount;
this.comfortLevel = comfortLevel;
}
public int getPassengerCount() {
return passengerCount;
}
public int getComfortLevel() {
return comfortLevel;
}
}
/**
* Клас, що описує вагон для багажу.
*/
class BaggageCarriage extends RollingStock {
private int baggageCount;
public BaggageCarriage(int number, int baggageCount) {
super(number);
this.baggageCount = baggageCount;
}
public int getBaggageCount() {
return baggageCount;
}
}
/**
* Клас, що описує пасажирський потяг.
*/
class PassengerTrain {
private RollingStock[] rollingStock;
public PassengerTrain(RollingStock[] rollingStock) {
this.rollingStock = rollingStock;
}
public int getTotalPassengerCount() {
int totalPassengerCount = 0;
for (RollingStock stock : rollingStock) {
if (stock instanceof PassengerCarriage) {
PassengerCarriage carriage = (PassengerCarriage) stock;
totalPassengerCount += carriage.getPassengerCount();
}
}
return totalPassengerCount;
}
public int getTotalBaggageCount() {
int totalBaggageCount = 0;
for (RollingStock stock : rollingStock) {
if (stock instanceof BaggageCarriage) {
BaggageCarriage carriage = (BaggageCarriage) stock;
totalBaggageCount += carriage.getBaggageCount();
}
}
return totalBaggageCount;
}
public void sortByComfortLevel() {
Arrays.sort(rollingStock, new Comparator<RollingStock>() {
@Override
public int compare(RollingStock o1, RollingStock o2) {
if (o1 instanceof PassengerCarriage && o2 instanceof PassengerCarriage) {
PassengerCarriage carriage1 = (PassengerCarriage) o1;
PassengerCarriage carriage2 = (PassengerCarriage) o2;
return carriage1.getComfortLevel() - carriage2.getComfortLevel();
}
return 0;
}
});
}
public RollingStock findCarriageByPassengerCountRange(int minPassengerCount, int maxPassengerCount) {
for (RollingStock stock : rollingStock) {
if (stock instanceof PassengerCarriage) {
PassengerCarriage carriage = (PassengerCarriage) stock;
if (carriage.getPassengerCount() >= minPassengerCount && carriage.getPassengerCount() <= maxPassengerCount) {
return carriage;
}
}
}
return null;
}
}
/**
* Головний клас програми.
*/
public class Main {
public static void main(String[] args) {
// Створення вагонів потягу
RollingStock[] rollingStock = new RollingStock[5];
rollingStock[0] = new PassengerCarriage(1, 40, 3);
rollingStock[1] = new PassengerCarriage(2, 30, 2);
rollingStock[2] = new BaggageCarriage(3, 50);
rollingStock[3] = new PassengerCarriage(4, 20, 1);
rollingStock[4] = new PassengerCarriage(5, 35, 2);
// Створення пасажирського потягу
PassengerTrain train = new PassengerTrain(rollingStock);
// Розрахунок загальної кількості пасажирів та багажу в потязі
int totalPassengerCount = train.getTotalPassengerCount();
int totalBaggageCount = train.getTotalBaggageCount();
System.out.println("Total passenger count: " + totalPassengerCount);
System.out.println("Total baggage count: " + totalBaggageCount);
// Сортування вагонів за рівнем комфортності
train.sortByComfortLevel();
System.out.println("Sorted carriages by comfort level:");
for (RollingStock stock : rollingStock) {
if (stock instanceof PassengerCarriage) {
PassengerCarriage carriage = (PassengerCarriage) stock;
System.out.println("Carriage " + carriage.getNumber() + ", Comfort Level: " + carriage.getComfortLevel());
}
}
// Знаходження вагона з пасажирськими місцями в заданому діапазоні кількості пасажирів
int minPassengerCount = 25;
int maxPassengerCount = 40;
RollingStock foundCarriage = train.findCarriageByPassengerCountRange(minPassengerCount, maxPassengerCount);
if (foundCarriage != null) {
System.out.println("Found carriage with passenger count in range (" + minPassengerCount + "-" + maxPassengerCount + "): " + foundCarriage.getNumber());
} else {
System.out.println("No carriage found with passenger count in range (" + minPassengerCount + "-" + maxPassengerCount + ")");
}
}
}

View File

@@ -1,11 +0,0 @@
<?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>