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

Commit 08f2bfe

Browse files
authored
Merge pull request #611 from Boiiterra/some_to_last
Выполнены все задания с 21 по 32 включительно
2 parents 44c31f5 + aa1d995 commit 08f2bfe

File tree

47 files changed

+2066
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2066
-0
lines changed

students/23K0341/23K0341-p21/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0341</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0341-p21</artifactId>
12+
<description>Второе задание</description>
13+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public final class Main {
4+
5+
private Main() {
6+
7+
}
8+
9+
public static void main(String[] args) {
10+
System.out.println("вторая практическая работа!");
11+
}
12+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
7+
/**
8+
* Написать метод для конвертации массива строк/чисел в
9+
* список.
10+
*/
11+
12+
public abstract class Task1 {
13+
public static <E> List<E> arrToL(E[] arr) {
14+
return new ArrayList<E>(Arrays.asList(arr));
15+
}
16+
17+
public static void main(String[] args) {
18+
Integer[] ex = new Integer[]{1, 3, 5, 7, 2, 6, 8, 19};
19+
System.out.println("Example " + ex.getClass() + ": " + Arrays.toString(ex));
20+
List<Integer> list = arrToL(ex);
21+
System.out.println("Example " + list.getClass() + ": " + list);
22+
}
23+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.nio.BufferOverflowException;
4+
5+
/**
6+
* Написать класс, который умеет хранить в себе массив любых
7+
* типов данных (int, long etc.).
8+
*/
9+
10+
public abstract class Task2 {
11+
12+
static class Storage {
13+
int length = 0;
14+
boolean dynamic;
15+
private Object[] data;
16+
17+
private void resize() {
18+
Object[] nData = new Object[data.length * 2];
19+
System.arraycopy(data, 0, nData, 0, data.length);
20+
data = nData;
21+
}
22+
23+
public void add(Object el) {
24+
if (length + 1 >= data.length) {
25+
if (dynamic) {
26+
resize();
27+
} else {
28+
throw new BufferOverflowException();
29+
}
30+
}
31+
32+
data[length++] = el;
33+
}
34+
35+
@Override
36+
public String toString() {
37+
StringBuilder str = new StringBuilder("Data [");
38+
for (int i = 0; i < length; i++) {
39+
str.append(" ").append(i).append(": ").append(data[i]);
40+
if (i + 1 < length) {
41+
str.append(",");
42+
}
43+
}
44+
str.append(" ]");
45+
46+
return str.toString();
47+
}
48+
49+
Storage(int len) {
50+
this(len, false);
51+
}
52+
53+
Storage(int len, boolean dynamic) {
54+
data = new Object[len];
55+
this.dynamic = dynamic;
56+
}
57+
}
58+
59+
public static void main(String[] args) {
60+
int n = 5;
61+
Storage cont = new Storage(20);
62+
63+
for (int i = 0; i < n; i++) {
64+
cont.add(i);
65+
cont.add(1.757 * i);
66+
cont.add("Hello there no." + i + 5);
67+
}
68+
69+
System.out.println(cont);
70+
}
71+
}

students/23K0341/23K0341-p22/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0341</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0341-p22</artifactId>
12+
<description>Второе задание</description>
13+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public final class Main {
4+
5+
private Main() {
6+
7+
}
8+
9+
public static void main(String[] args) {
10+
System.out.println("вторая практическая работа!");
11+
}
12+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.Scanner;
4+
import java.util.Stack;
5+
6+
/**
7+
* Напишите программу-калькулятор арифметических
8+
* выражений записанных в обратной польской нотации (RPN-калькулятор).
9+
*/
10+
11+
public abstract class Task1 {
12+
private static double calculate(String expr) {
13+
Stack<Double> stack = new Stack<Double>();
14+
String[] tokens = expr.split(" ");
15+
16+
for (String token : tokens) {
17+
switch (token) {
18+
case "+":
19+
stack.push(stack.pop() + stack.pop());
20+
break;
21+
case "-":
22+
double oops = stack.pop();
23+
stack.push(stack.pop() - oops);
24+
break;
25+
case "*":
26+
stack.push(stack.pop() * stack.pop());
27+
break;
28+
case "/":
29+
double div = stack.pop();
30+
if (div == 0) {
31+
throw new IllegalArgumentException("Division by zero.");
32+
}
33+
stack.push(stack.pop() / div);
34+
break;
35+
default:
36+
try {
37+
double val = Double.parseDouble(token);
38+
stack.push(val);
39+
} catch (Exception e) {
40+
// New exception is thrown in catch block, original stack trace may be lost
41+
throw new IllegalArgumentException("Illegal token: " + token + "; extra: ", e);
42+
}
43+
break;
44+
}
45+
}
46+
47+
if (stack.size() != 1) {
48+
throw new IllegalArgumentException("Illegal input: " + expr + ".");
49+
}
50+
51+
return stack.pop();
52+
}
53+
54+
public static void main(String[] args) {
55+
try (Scanner sc = new Scanner(System.in)) {
56+
System.out.print("Please enter expression: ");
57+
String val = sc.nextLine();
58+
try {
59+
double res = calculate(val);
60+
System.out.println("Result: " + res);
61+
} catch (Exception e) {
62+
System.out.println(e.getMessage());
63+
}
64+
}
65+
}
66+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import javax.swing.UIManager;
4+
import javax.swing.JFrame;
5+
import javax.swing.JButton;
6+
import javax.swing.JPanel;
7+
import javax.swing.JTextField;
8+
import java.awt.Font;
9+
import java.awt.Color;
10+
11+
/**
12+
* Напишите графический интерфейс для калькулятора,
13+
* используя знания полученные ранее при програмиировании GUI с
14+
* использованием SWING и AWT. Используйте паттерн проектирования
15+
* MVC. Интерфейс может выглядеть как на рис. 22.1 или как на рис. 22.2
16+
*/
17+
18+
public abstract class Task2 {
19+
static JFrame frame;
20+
static JTextField l;
21+
String[] ns;
22+
String la;
23+
int action;
24+
int cn;
25+
26+
public static void main(String[] args) {
27+
frame = new JFrame("Calculator");
28+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
29+
try {
30+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
31+
} catch (Exception e) {
32+
System.err.println(e.getMessage());
33+
}
34+
35+
36+
l = new JTextField(10);
37+
l.setEditable(false);
38+
l.setCaretColor(Color.WHITE);
39+
40+
Font font = new Font("Arial", Font.PLAIN, 28);
41+
l.setFont(font);
42+
l.setHorizontalAlignment(JTextField.CENTER);
43+
44+
JButton b0 = new FontyButton("0");
45+
JButton b1 = new FontyButton("1");
46+
JButton b2 = new FontyButton("2");
47+
JButton b3 = new FontyButton("3");
48+
JButton b4 = new FontyButton("4");
49+
JButton b5 = new FontyButton("5");
50+
JButton b6 = new FontyButton("6");
51+
JButton b7 = new FontyButton("7");
52+
JButton b8 = new FontyButton("8");
53+
JButton b9 = new FontyButton("9");
54+
55+
JButton f = new FontyButton(".");
56+
JButton a = new FontyButton("+");
57+
JButton s = new FontyButton("-");
58+
JButton d = new FontyButton("/");
59+
JButton m = new FontyButton("*");
60+
JButton e = new FontyButton("=");
61+
62+
JPanel p = new JPanel();
63+
64+
p.add(l);
65+
66+
p.add(b1);
67+
p.add(b2);
68+
p.add(b3);
69+
p.add(a);
70+
71+
p.add(b4);
72+
p.add(b5);
73+
p.add(b6);
74+
p.add(s);
75+
76+
p.add(b7);
77+
p.add(b8);
78+
p.add(b9);
79+
p.add(m);
80+
81+
p.add(f);
82+
p.add(b0);
83+
p.add(e);
84+
p.add(d);
85+
86+
frame.add(p);
87+
frame.setSize(270, 300);
88+
frame.setVisible(true);
89+
}
90+
91+
Task2() {
92+
ns = new String[]{"", ""};
93+
action = -1;
94+
la = "";
95+
cn = 0;
96+
}
97+
98+
static class FontyButton extends JButton {
99+
FontyButton(String text) {
100+
setText(text);
101+
setFont(new Font("Arial", Font.PLAIN, 30));
102+
}
103+
}
104+
}

students/23K0341/23K0341-p23/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0341</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0341-p23</artifactId>
12+
<description>Второе задание</description>
13+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public final class Main {
4+
5+
private Main() {
6+
7+
}
8+
9+
public static void main(String[] args) {
10+
System.out.println("вторая практическая работа!");
11+
}
12+
}

0 commit comments

Comments
 (0)