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

Лабораторные №21 - №30 #696

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions students/23K0089/23K0089-p21/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0089</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0089-p21</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.mirea.practice.s23k0089;

public final class Main {

private Main() {

}

public static void main(String[] args) {
System.out.println("первая практическая работа!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ru.mirea.practice.s23k0089.task1;

import java.util.ArrayList;
import java.util.List;

public abstract class Main {
public static <T> List<T> arrToList(T[] array) {
List<T> list = new ArrayList<>(array.length);
for (T element : array) {
list.add(element);
}
return list;
}

public static void main(String[] args) {
Integer[] arr = {1, 2, 3, 4, 5};
List<Integer> list = arrToList(arr);
System.out.println(list);

String[] arr1 = {"one", "two", "three", "banana"};
List<String> list1 = arrToList(arr1);
System.out.println(list1);
}
}

13 changes: 13 additions & 0 deletions students/23K0089/23K0089-p23/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0089</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0089-p23</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.mirea.practice.s23k0089;

public final class Main {

private Main() {

}

public static void main(String[] args) {
System.out.println("первая практическая работа!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package ru.mirea.practice.s23k0089.task1;

public class ArrayQueue {
private double[] elements;
private int head;
private int tail;
private int size;

public ArrayQueue(int capacity) {
this.elements = new double[capacity];
this.head = 0;
this.tail = 0;
this.size = 0;
}

public void enqueue(double value) {
if (size == elements.length) {
throw new IllegalStateException("Очередь переполнена");
}
elements[tail] = value;
tail = (tail + 1) % elements.length;
size++;
}

public double dequeue() {
if (isEmpty()) {
throw new IllegalStateException("Очередь пуста");
}
double value = elements[head];
head = (head + 1) % elements.length;
size--;
return value;
}

public double element() {
if (isEmpty()) {
throw new IllegalStateException("Очередь пуста");
}
return elements[head];
}

public int size() {
return size;
}

public boolean isEmpty() {
return size == 0;
}

public void clear() {
head = 0;
tail = 0;
size = 0;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ru.mirea.practice.s23k0089.task1;

public class ArrayQueueADt {
private double[] elements;
private int head;
private int tail;
private int size;

public ArrayQueueADt(int capacity) {
elements = new double[capacity];
head = 0;
tail = 0;
size = 0;
}

public void enqueue(double value) {
if (size == elements.length) {
throw new IllegalStateException("Очередь переполнена");
}
elements[tail] = value;
tail = (tail + 1) % elements.length;
size++;
}

public double dequeue() {
if (isEmpty()) {
throw new IllegalStateException("Очередь пуста");
}
double value = elements[head];
head = (head + 1) % elements.length;
size--;
return value;
}

public double element() {
if (isEmpty()) {
throw new IllegalStateException("Очередь пуста");
}
return elements[head];
}

public int size() {
return size;
}

public boolean isEmpty() {
return size == 0;
}

public void clear() {
head = 0;
tail = 0;
size = 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package ru.mirea.practice.s23k0089.task1;

public abstract class ArrayQueueModule {
private static final int capacity = 10;
private static double[] elements;
private static int head;
private static int tail;
private static int size;

static {
elements = new double[capacity];
head = 0;
tail = 0;
size = 0;
}

public static void enqueue(double value) {
if (size == elements.length) {
throw new IllegalStateException("Очередь переполнена");
}
elements[tail] = value;
tail = (tail + 1) % elements.length;
size++;
}

public static double dequeue() {
if (isEmpty()) {
throw new IllegalStateException("Очередь пуста");
}
double value = elements[head];
head = (head + 1) % elements.length;
size--;
return value;
}

public static double element() {
if (isEmpty()) {
throw new IllegalStateException("Очередь пуста");
}
return elements[head];
}

public static int size() {
return size;
}

public static boolean isEmpty() {
return size == 0;
}

public static void clear() {
head = 0;
tail = 0;
size = 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ru.mirea.practice.s23k0089.task1;

public abstract class ArrayQueueTest {
public static void main(String[] args) {
ArrayQueue queue = new ArrayQueue(5);

System.out.println("Очередь пустая: " + queue.isEmpty());

queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(3);

System.out.println("Первый элемент: " + queue.element());
System.out.println("Размер очереди: " + queue.size());
System.out.println("Удалённый элемент: " + queue.dequeue());
System.out.println("Элемент после удаления: " + queue.element());

queue.clear();

System.out.println("Очередь пустая после очистки: " + queue.isEmpty());

try {
queue.dequeue();
} catch (IllegalStateException e) {
System.out.println(e.getMessage());
}
}
}
13 changes: 13 additions & 0 deletions students/23K0089/23K0089-p24/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0089</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0089-p24</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.mirea.practice.s23k0089;

public final class Main {

private Main() {

}

public static void main(String[] args) {
System.out.println("первая практическая работа!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ru.mirea.practice.s23k0089.task1;


public class Complex {
private double real;
private double image;

public Complex(double real, double image) {
this.real = real;
this.image = image;
}

public Complex() {
this.real = 0;
this.image = 0;
}

public double getReal() {
return real;
}

public void setReal(double real) {
this.real = real;
}

public double getImage() {
return image;
}

public void setImage(double image) {
this.image = image;
}

@Override
public String toString() {
String complexString;
if (image >= 0) {
complexString = String.format("%f + %fi", real, image);
} else {
complexString = String.format("%f - %fi", real, Math.abs(image));
}
return complexString;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.mirea.practice.s23k0089.task1;

public interface ComplexAbstractFactory {
Complex createComplex();

Complex createComplex(int real, int image);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ru.mirea.practice.s23k0089.task1;

public class ComplexFactory implements ComplexAbstractFactory {
@Override
public Complex createComplex() {
return new Complex();
}

@Override
public Complex createComplex(int real, int image) {
return new Complex(real, image);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ru.mirea.practice.s23k0089.task2;

public abstract class AbstractChairFactory {
abstract VictorianChair createVictorianChair(int age);

abstract MagicChair createMagicChair();

abstract FunctionalChair createFunctionalChair();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ru.mirea.practice.s23k0089.task2;

public interface Chair {

}
Loading
Loading