Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Приготовились 21-26 + 28-29 (получились вкусно) | остальные в духовке #611

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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/23K0341/23K0341-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>23K0341</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0341-p21</artifactId>
<description>Второе задание</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.mirea.practice.s0000001;

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,23 @@
package ru.mirea.practice.s0000001;

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

/**
* Написать метод для конвертации массива строк/чисел в
* список.
*/

public abstract class Task1 {
public static <E> List<E> arrToL(E[] arr) {
return new ArrayList<E>(Arrays.asList(arr));
}

public static void main(String[] args) {
Integer[] ex = new Integer[]{1, 3, 5, 7, 2, 6, 8, 19};
System.out.println("Example " + ex.getClass() + ": " + Arrays.toString(ex));
List<Integer> list = arrToL(ex);
System.out.println("Example " + list.getClass() + ": " + list);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package ru.mirea.practice.s0000001;

import java.nio.BufferOverflowException;

/**
* Написать класс, который умеет хранить в себе массив любых
* типов данных (int, long etc.).
*/

public abstract class Task2 {

static class Storage {
int length = 0;
boolean dynamic;
private Object[] data;

private void resize() {
Object[] nData = new Object[data.length * 2];
System.arraycopy(data, 0, nData, 0, data.length);
data = nData;
}

public void add(Object el) {
if (length + 1 >= data.length) {
if (dynamic) {
resize();
} else {
throw new BufferOverflowException();
}
}

data[length++] = el;
}

@Override
public String toString() {
StringBuilder str = new StringBuilder("Data [");
for (int i = 0; i < length; i++) {
str.append(" ").append(i).append(": ").append(data[i]);
if (i + 1 < length) {
str.append(",");
}
}
str.append(" ]");

return str.toString();
}

Storage(int len) {
this(len, false);
}

Storage(int len, boolean dynamic) {
data = new Object[len];
this.dynamic = dynamic;
}
}

public static void main(String[] args) {
int n = 5;
Storage cont = new Storage(20);

for (int i = 0; i < n; i++) {
cont.add(i);
cont.add(1.757 * i);
cont.add("Hello there no." + i + 5);
}

System.out.println(cont);
}
}
13 changes: 13 additions & 0 deletions students/23K0341/23K0341-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>23K0341</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0341-p22</artifactId>
<description>Второе задание</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.mirea.practice.s0000001;

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,66 @@
package ru.mirea.practice.s0000001;

import java.util.Scanner;
import java.util.Stack;

/**
* Напишите программу-калькулятор арифметических
* выражений записанных в обратной польской нотации (RPN-калькулятор).
*/

public abstract class Task1 {
private static double calculate(String expr) {
Stack<Double> stack = new Stack<Double>();
String[] tokens = expr.split(" ");

for (String token : tokens) {
switch (token) {
case "+":
stack.push(stack.pop() + stack.pop());
break;
case "-":
double oops = stack.pop();
stack.push(stack.pop() - oops);
break;
case "*":
stack.push(stack.pop() * stack.pop());
break;
case "/":
double div = stack.pop();
if (div == 0) {
throw new IllegalArgumentException("Division by zero.");
}
stack.push(stack.pop() / div);
break;
default:
try {
double val = Double.parseDouble(token);
stack.push(val);
} catch (Exception e) {
// New exception is thrown in catch block, original stack trace may be lost
throw new IllegalArgumentException("Illegal token: " + token + "; extra: ", e);
}
break;
}
}

if (stack.size() != 1) {
throw new IllegalArgumentException("Illegal input: " + expr + ".");
}

return stack.pop();
}

public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
System.out.print("Please enter expression: ");
String val = sc.nextLine();
try {
double res = calculate(val);
System.out.println("Result: " + res);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package ru.mirea.practice.s0000001;

import javax.swing.UIManager;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.Font;
import java.awt.Color;

/**
* Напишите графический интерфейс для калькулятора,
* используя знания полученные ранее при програмиировании GUI с
* использованием SWING и AWT. Используйте паттерн проектирования
* MVC. Интерфейс может выглядеть как на рис. 22.1 или как на рис. 22.2
*/

public abstract class Task2 {
static JFrame frame;
static JTextField l;
String[] ns;
String la;
int action;
int cn;

public static void main(String[] args) {
frame = new JFrame("Calculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.err.println(e.getMessage());
}


l = new JTextField(10);
l.setEditable(false);
l.setCaretColor(Color.WHITE);

Font font = new Font("Arial", Font.PLAIN, 28);
l.setFont(font);
l.setHorizontalAlignment(JTextField.CENTER);

JButton b0 = new FontyButton("0");
JButton b1 = new FontyButton("1");
JButton b2 = new FontyButton("2");
JButton b3 = new FontyButton("3");
JButton b4 = new FontyButton("4");
JButton b5 = new FontyButton("5");
JButton b6 = new FontyButton("6");
JButton b7 = new FontyButton("7");
JButton b8 = new FontyButton("8");
JButton b9 = new FontyButton("9");

JButton f = new FontyButton(".");
JButton a = new FontyButton("+");
JButton s = new FontyButton("-");
JButton d = new FontyButton("/");
JButton m = new FontyButton("*");
JButton e = new FontyButton("=");

JPanel p = new JPanel();

p.add(l);

p.add(b1);
p.add(b2);
p.add(b3);
p.add(a);

p.add(b4);
p.add(b5);
p.add(b6);
p.add(s);

p.add(b7);
p.add(b8);
p.add(b9);
p.add(m);

p.add(f);
p.add(b0);
p.add(e);
p.add(d);

frame.add(p);
frame.setSize(270, 300);
frame.setVisible(true);
}

Task2() {
ns = new String[]{"", ""};
action = -1;
la = "";
cn = 0;
}

static class FontyButton extends JButton {
FontyButton(String text) {
setText(text);
setFont(new Font("Arial", Font.PLAIN, 30));
}
}
}
13 changes: 13 additions & 0 deletions students/23K0341/23K0341-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>23K0341</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0341-p23</artifactId>
<description>Второе задание</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.mirea.practice.s0000001;

public final class Main {

private Main() {

}

public static void main(String[] args) {
System.out.println("вторая практическая работа!");
}
}
Loading
Loading