podkorytova_yulia_lab_2 is ready

This commit is contained in:
yulia 2023-12-15 16:29:17 +04:00
parent f2adafe2e1
commit 6ddd513f75
13 changed files with 142 additions and 0 deletions

View File

@ -0,0 +1,8 @@
84
6
56
4
32
47
4
62

View File

@ -0,0 +1,6 @@
1
65
93
91
20
62

View File

@ -0,0 +1,6 @@
43
60
31
13
2
87

View File

@ -0,0 +1,20 @@
version: '3'
services:
worker-1: # название 1 сервиса
build: # директива build для сборки образа
context: /worker-1
dockerfile: Dockerfile
volumes: # монтирование папок
- .\data:/var/data
- .\result:/var/result
worker-2: # название 2 сервиса
build: # директива build для сборки образа
context: /worker-2
dockerfile: Dockerfile
depends_on: # зависимость сервисов
- worker-1
volumes: # монтирование папок
- .\data:/var/data
- .\result:/var/result

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -0,0 +1,18 @@
# использование образа java
FROM openjdk:17
# создание директорий для файлов
RUN mkdir /var/data
RUN mkdir /var/result
# установка рабочей директории проекта
WORKDIR /app
# копирование исходных файлов
COPY src /app/src
# компиляция
RUN javac /app/src/App1.java
# запуск java-приложения
CMD ["java", "-cp", "/app/src", "App1"]

View File

@ -0,0 +1,32 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
public class App1 {
public static void main(String[] args) {
File dataDirectory = new File("/var/data");
File[] files = dataDirectory.listFiles();
if (files.length > 0) {
File shortestFileName = files[0];
for (File file : files) {
if (file.getName().length() < shortestFileName.getName().length()) {
shortestFileName = file;
}
}
Path sourcePath = shortestFileName.toPath();
Path destinationPath = new File("/var/result/data.txt").toPath();
try {
Files.copy(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING);
System.out.println("Файл успешно перемещен.");
} catch (IOException e) {
System.out.println("Ошибка при перемещении файла: " + e.getMessage());
}
} else {
System.out.println("Каталог /var/data пустой.");
}
}
}

View File

@ -0,0 +1,18 @@
# использование образа java
FROM openjdk:17
# создание директорий для файлов
RUN mkdir /var/data
RUN mkdir /var/result
# установка рабочей директории проекта
WORKDIR /app
# копирование исходных файлов
COPY src /app/src
# компиляция
RUN javac /app/src/App2.java
# запуск java-приложения
CMD ["java", "-cp", "/app/src", "App2"]

View File

@ -0,0 +1,34 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class App2 {
public static void main(String[] args) {
String inputFile = "/var/result/data.txt";
String outputFile = "/var/result/result.txt";
try (BufferedReader reader = new BufferedReader(new FileReader(inputFile));
FileWriter writer = new FileWriter(outputFile)) {
String line;
int smallestNumber = Integer.MAX_VALUE;
int count = 0;
while ((line = reader.readLine()) != null) {
int number = Integer.parseInt(line);
if (number < smallestNumber) {
smallestNumber = number;
count = 1;
} else if (number == smallestNumber) {
count++;
}
}
writer.write(String.valueOf(count));
System.out.println("Количество чисел, равных наименьшему значению: " + count);
} catch (IOException e) {
System.out.println("Ошибка при обработке файла: " + e.getMessage());
}
}
}