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

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

Merged
merged 1 commit into from
Dec 13, 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/23K0340/23K0340-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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>23K0340</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0340-p21</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ru.mirea.practice.s0000001;

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

public abstract class First {
public static void main(String[] args) {
String[] s = new String[5];
s[0] = "a";
s[1] = "b";
s[2] = "c";
s[3] = "d";
s[4] = "e";
List<String> s1 = new LinkedList<>();
s1 = arraytolst(s);
System.out.println(s1.get(0));
}

public static <T> List<T> arraytolst(T[] arr) {
int len = arr.length;
ArrayList<T> lst = new ArrayList<>();
for (int i = 0;i < len;i++) {
lst.add(arr[i]);
}
return (List<T>) lst;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ru.mirea.practice.s0000001;

public abstract class Second {
public static class Mass<T> {
private Object[] arr;
private int size;

public Mass(int size) {
this.size = size;
this.arr = new Object[size];
}

public void add(T t, int i) {
arr[i] = t;
}

public <T> T get(int i) {
return (T) arr[i];
}
}

public static void main(String[] args) {
Mass<String> mas = new Mass<>(5);
Mass<Double> mass = new Mass<Double>(5);
for (int i = 0; i < 5; i++) {
mas.add("a", i);
mass.add(Math.pow(2, i), i);
}
System.out.println((String)mas.get(3));
System.out.println((Double)mass.get(2));
}
}
13 changes: 13 additions & 0 deletions students/23K0340/23K0340-p22/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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>23K0340</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0340-p22</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ru.mirea.practice.s0000001;

public class Calc {
private Stack stack;
private int size;

public Calc(int size) {
this.size = size;
this.stack = new Stack(size);
}

public int getSize() {
return size;
}

public void iter(String data) {
if (isStringDouble(data)) {
this.stack.push(Double.parseDouble(data));
} else {
if ("*".equals(data)) {
this.stack.push(this.stack.pop() * this.stack.pop());
} else if ("/".equals(data)) {
this.stack.push(Math.pow(this.stack.pop(), -1) * this.stack.pop());
} else if ("+".equals(data)) {
this.stack.push(this.stack.pop() + this.stack.pop());
} else if ("-".equals(data)) {
this.stack.push(this.stack.pop() * (-1) + this.stack.pop());
} else {
System.out.println("Incorrect input");
}
}
}

public boolean isStringDouble(String s) {
try {
Double.parseDouble(s);
return true;
} catch (NumberFormatException ex) {
return false;
}
}

public double end() {
return this.stack.pop();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ru.mirea.practice.s0000001;

import java.util.Scanner;

public abstract class Main {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
Calc calc = new Calc(10);
boolean end = true;
String s = "";
while (end) {
s = sc.nextLine();
if ("".equals(s)) {
System.out.println(calc.end());
break;
}
calc.iter(s);
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package ru.mirea.practice.s0000001;

public class Stack {
private double[] arr;
private int top;
private int capacity;

public Stack(int capacity) {
this.arr = new double[capacity];
this.top = -1;
this.capacity = capacity;
}

public void push(double data) {
if (isFull()) {
System.out.println("The stack is full");
System.exit(1);
}
this.arr[++top] = data;
}

public double pop() {
if (isEmpty()) {
System.out.println("The stack is empty");
System.exit(1);
}
return arr[top--];
}

public boolean isFull() {
return top == capacity - 1;
}

public boolean isEmpty() {
return top == -1;
}

public int getTop() {
return top;
}
}
13 changes: 13 additions & 0 deletions students/23K0340/23K0340-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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>23K0340</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0340-p23</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package ru.mirea.practice.s0000001;

public class ArrayQueueModule {
private int size;
private int[] queue;
private int front;
private int rear;
private int n;

public ArrayQueueModule(int size) {
this.size = size;
this.queue = new int[size];
this.front = 0;
this.rear = -1;
this.n = 0;
}

public void clear() {
while (n != rear) {
front = (front + 1) % size;
n--;
}
}

public int element() {
if (rear == -1) {
System.out.println("The queue is empty");
}
return queue[rear];
}

public void enqueue(int value) {
if (n == size) {
System.out.println("The queue is full");
return;
}
rear = (rear + 1) % size;
queue[rear] = value;
n++;
}

public int dequeue() {
if (n == 0) {
System.out.println("The queue if empty");
return -1;
}
int value = queue[front];
front = (front + 1) % size;
n--;
return value;
}

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

public boolean isFull() {
return n == size;
}

public int size() {
return n;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ru.mirea.practice.s0000001;

public class ArrayQueueadt {
private Node front;
private Node rear;

public ArrayQueueadt() {
this.front = null;
this.rear = null;
}

public int element() {
return rear.data;
}

public void enqueue(int data) {
Node node = new Node(data);
if (rear != null) {
rear.next = node;
}
rear = node;
if (front == null) {
front = node;
}
}

public void clear() {
this.rear = null;
this.front = null;
}

public int dequeue() {
if (front == null) {
return 0;
}
int data = front.data;
front = front.next;
if (front == null) {
rear = null;
}
return data;
}

public boolean isEmpty() {
return front == null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ru.mirea.practice.s0000001;

public class Node {
int data;
Node next;

public Node(int data) {
this.data = data;
this.next = null;
}
}
13 changes: 13 additions & 0 deletions students/23K0340/23K0340-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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>23K0340</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0340-p24</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ru.mirea.practice.s0000001;

public interface AbstractChairFactory {
VictorianChair createVictorianChair();

MagicChair createMagicChair();

FunctionalChair createFunctionalChair();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ru.mirea.practice.s0000001;

public interface Chair {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.mirea.practice.s0000001;

public class ChairFactory implements AbstractChairFactory {
@Override
public VictorianChair createVictorianChair() {
return new VictorianChair(0);
}

@Override
public FunctionalChair createFunctionalChair() {
return new FunctionalChair();
}

@Override
public MagicChair createMagicChair() {
return new MagicChair();
}
}
Loading
Loading