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

Features/lab1 #638

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.mirea.practice.s23k0155.task1;
package ru.mirea.practice.s23k0155.task12;


class Circle extends Shape {
Expand Down Expand Up @@ -28,4 +28,4 @@ public double getArea() {
public double getPerimeter() {
return 2 * Math.PI * radius;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.mirea.practice.s23k0155.task1;
package ru.mirea.practice.s23k0155.task12;

public abstract class Main {
public static void main(String[] args) {
Expand All @@ -11,4 +11,4 @@ public static void main(String[] args) {
System.out.println("Rectangle Area: " + rectangle.getArea());
System.out.println("Rectangle Perimeter: " + rectangle.getPerimeter());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.mirea.practice.s23k0155.task1;
package ru.mirea.practice.s23k0155.task12;

class Rectangle extends Shape {
private double width;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.mirea.practice.s23k0155.task1;
package ru.mirea.practice.s23k0155.task12;


abstract class Shape {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.mirea.practice.s23k0155.task1;
package ru.mirea.practice.s23k0155.task12;


public class IntArrayLinkedList {
Expand Down Expand Up @@ -33,4 +33,4 @@ public static void main(String[] args) {
System.out.println("List elements:");
list.printList();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.mirea.practice.s23k0155.task1;
package ru.mirea.practice.s23k0155.task12;


class IntArrayNode {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.mirea.practice.s23k0155.task1;
package ru.mirea.practice.s23k0155.task12;

public abstract class Exception1 {
public static void exceptionDemo() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.mirea.practice.s23k0155.task1;
package ru.mirea.practice.s23k0155.task12;

public abstract class Main {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.mirea.practice.s23k0155.task1;
package ru.mirea.practice.s23k0155.task12;

abstract class Calculator {
public static <T extends Number> double sum(T a, T b) {
Expand All @@ -19,4 +19,4 @@ public static <T extends Number> double divide(T a, T b) {
}
return a.doubleValue() / b.doubleValue();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.mirea.practice.s23k0155.task1;
package ru.mirea.practice.s23k0155.task12;

class MinMax<T extends Comparable<T>> {
private T[] array;
Expand Down Expand Up @@ -26,4 +26,4 @@ public T getMax() {
}
return max;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.mirea.practice.s23k0155.task1;
package ru.mirea.practice.s23k0155.task12;

public abstract class Test {
public static void main(String[] args) {
Expand All @@ -15,4 +15,4 @@ public static void main(String[] args) {
System.out.println("Multiply: " + Calculator.multiply(5, 3));
System.out.println("Divide: " + Calculator.divide(5, 3));
}
}
}
13 changes: 13 additions & 0 deletions students/23K0155/23K0155-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>23K0155</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0155-p21</artifactId>
<description>Двацать первое задание</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ru.mirea.practice.s23k0155;

public class ArrayClass {
private Object[] array;
private int size;
private int currentElement;

public ArrayClass(int size) {
this.size = size;
this.currentElement = 0;
this.array = new Object[size];
}

public void addElement(Object ellement) {
this.array[currentElement++] = ellement;
}

// Метод, который возвращает любой элемент массива по индексу.
public Object getElement(int index) {
if (index >= size) {
return "Ошибка ввода данных: выход за пределы массива";
} else {
return array[index];
}
}

public void printArray() {
System.out.print("[");
for (int i = 0; i < size; i++) {
System.out.print(array[i] + " ");
}
System.out.print("]");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ru.mirea.practice.s23k0155;

public abstract class Test {
public static void main(String[] args) {
ArrayClass tester = new ArrayClass(4);
tester.addElement(1);
tester.addElement(123.8766);
tester.addElement(1234567890123456789L);
tester.addElement("Number");
System.out.println("Элепмент под индексем 3: " + tester.getElement(3));
System.out.println("все эллементы:");
tester.printArray();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
1) аписать класс, который умеет хранить в себе массив любых
типов данных (int, long etc.).

2) Реализовать метод, который возвращает любой элемент
массива по индексу.

13 changes: 13 additions & 0 deletions students/23K0155/23K0155-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="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>23K0155</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0155-p22</artifactId>
<description>Двацать второе задание</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ru.mirea.practice.s23k0155;

public class RpnCalculator {
private Stack stack;

public RpnCalculator(int size) {
stack = new Stack(size);
}

public double evaluate(String expression) {
String[] strings = expression.split(" ");
for (String element : strings) {
try {
float f = Float.parseFloat(element);
stack.push(f);
} catch (NumberFormatException e) {
performOperation(element);
}
}
return stack.pop();
}

private void performOperation(String operator) {
float secondOperand = stack.pop();
float firstOperand = stack.pop();
switch (operator) {
case "+":
stack.push(firstOperand + secondOperand);
break;
case "-":
stack.push(firstOperand - secondOperand);
break;
case "*":
stack.push(firstOperand * secondOperand);
break;
case "/":
if (secondOperand == 0) {
throw new ArithmeticException("Ошибка: Деление на ноль");
}
stack.push(firstOperand / secondOperand);
break;
default:
throw new IllegalArgumentException("Недопустимый оператор: " + operator);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package ru.mirea.practice.s23k0155;

class Stack {
// store elements of stack
private float[] arr;
// represent top of stack
private int top;
// total capacity of the stack
private int capacity;

// Creating a stack
Stack(int size) {
// initialize the array
// initialize the stack variables
arr = new float[size];
capacity = size;
top = -1;
}

// push elements to the top of stack
public void push(float x) {
if (isFull()) {
System.out.println("Stack OverFlow");
// terminates the program
System.exit(1);
}
// insert element on top of stack
System.out.println("Inserting " + x);
arr[++top] = x;
}

// pop elements from top of stack
public float pop() {
// if stack is empty
// no element to pop
if (isEmpty()) {
System.out.println("STACK EMPTY");
// terminates the program
System.exit(1);
}
// pop element from top of stack
return arr[top--];
}

// return size of the stack
public int getSize() {
return top + 1;
}

// check if the stack is empty
public Boolean isEmpty() {
return top == -1;
}

// check if the stack is full
public Boolean isFull() {
return top == capacity - 1;
}

// display elements of stack
public void printStack() {
for (int i = 0; i <= top; i++) {
System.out.print(arr[i] + ", ");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.mirea.practice.s23k0155;

public abstract class Test {
public static void main(String[] args) {
RpnCalculator calculator = new RpnCalculator(10);
System.out.println("16.1 3.9 + = " + calculator.evaluate("16.1 3.9 +"));
System.out.println("8 4 - = " + calculator.evaluate("8 4 -"));
System.out.println("28 0.5 * = " + calculator.evaluate("28 0.5 *"));
System.out.println("7 2 / = " + calculator.evaluate("7 2 /"));
System.out.println("3 4 + 2 * = " + calculator.evaluate("3 4 + 2 *"));

try {
System.out.println("38 0 / = " + calculator.evaluate("38 0 /"));
} catch (ArithmeticException e) {
System.out.println(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Напишите программу-калькулятор арифметических
выражений записанных в обратной польской нотации (RPN-калькулятор).

13 changes: 13 additions & 0 deletions students/23K0155/23K0155-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>23K0155</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0155-p23</artifactId>
<description>Двацать третье задание</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ru.mirea.practice.s23k0155.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;
}
}
Loading
Loading