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

Commit 4e48783

Browse files
committed
lab21-32
1 parent 44c31f5 commit 4e48783

File tree

72 files changed

+2454
-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.

72 files changed

+2454
-0
lines changed

students/23K0688/23K0688-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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>23K0688</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0688-p21</artifactId>
12+
<description>21 задание</description>
13+
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package ru.mirea.practice.s0000001.task1;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class Converter {
7+
8+
public List<String> starrtolist(String[] starr) {
9+
List<String> list = new ArrayList<>();
10+
for (String st : starr) {
11+
list.add(st);
12+
}
13+
return list;
14+
}
15+
16+
public List<Integer> intarrtolist(int[] array) {
17+
List<Integer> list = new ArrayList<>();
18+
for (int num : array) {
19+
list.add(num);
20+
}
21+
return list;
22+
}
23+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package ru.mirea.practice.s0000001.task1;
2+
3+
public abstract class Test {
4+
public static void main(String[] args) {
5+
String[] starr = {"ok,ko"};
6+
int[] intarr = {1,2,0};
7+
Converter c = new Converter();
8+
System.out.println(c.starrtolist(starr));
9+
System.out.println(c.intarrtolist(intarr));
10+
}
11+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package ru.mirea.practice.s0000001.task2;
2+
3+
public class Holder<D> {
4+
private int size;
5+
private D[] arr;
6+
7+
public Holder(int size) {
8+
this.size = size;
9+
}
10+
11+
public void setSize(int size) {
12+
this.size = size;
13+
}
14+
15+
public int getSize() {
16+
return size;
17+
}
18+
19+
public D[] getArr() {
20+
return arr;
21+
}
22+
23+
public void setArr(D[] arr) {
24+
D[] arrt = (D[]) new Object[size];
25+
System.arraycopy(arr, 0, arrt, 0, size);
26+
this.arr = arrt;
27+
}
28+
29+
public void print() {
30+
for (int i = 0;i < size;i++) {
31+
System.out.println(arr[i]);
32+
}
33+
}
34+
35+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package ru.mirea.practice.s0000001.task2;
2+
3+
public abstract class Test {
4+
public static void main(String[] args) {
5+
Holder<Integer> hint = new Holder<>(2);
6+
Integer[] intarr = {1,2};
7+
hint.setArr(intarr);
8+
System.out.println("hint:");
9+
hint.print();
10+
String[] starr = {"ok","ko"};
11+
Holder<String> hstr = new Holder<>(2);
12+
hstr.setArr(starr);
13+
System.out.println("hstr:");
14+
hstr.print();
15+
Holder<Double> hdob = new Holder<>(2);
16+
Double[] dobarr = {1.0,2.0};
17+
hdob.setArr(dobarr);
18+
System.out.println("hdob:");
19+
hdob.print();
20+
21+
}
22+
}

students/23K0688/23K0688-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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>23K0688</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0688-p22</artifactId>
12+
<description>22 задание</description>
13+
</project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ru.mirea.practice.s0000001.task0;
2+
3+
import java.util.Stack;
4+
5+
public class Calculus {
6+
public void calculate(StringBuilder numb) {
7+
Stack<Double> stack = new Stack<>();
8+
String[] st = numb.toString().split(" ");
9+
for (String sr : st) {
10+
switch (sr) {
11+
case "+":
12+
stack.push(stack.pop() + stack.pop());
13+
break;
14+
case "-":
15+
double num1 = stack.pop();
16+
double num2 = stack.pop();
17+
stack.push(num2 - num1);
18+
break;
19+
case "*":
20+
stack.push(stack.pop() * stack.pop());
21+
break;
22+
case "/":
23+
double num01 = stack.pop();
24+
double num02 = stack.pop();
25+
stack.push(num02 / num01);
26+
break;
27+
default:
28+
stack.push(Double.parseDouble(sr));
29+
break;
30+
}
31+
}
32+
System.out.println("res=" + stack.pop());
33+
}
34+
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package ru.mirea.practice.s0000001.task0;
2+
3+
import javax.swing.JButton;
4+
import javax.swing.JLabel;
5+
import javax.swing.SwingConstants;
6+
import javax.swing.JPanel;
7+
import javax.swing.JFrame;
8+
import java.awt.Dimension;
9+
import java.awt.event.ActionEvent;
10+
import java.awt.event.ActionListener;
11+
12+
public abstract class Test {
13+
public static void main(String[] args) {
14+
StringBuilder numb = new StringBuilder();
15+
final JButton b1 = new JButton("0");
16+
final JButton b2 = new JButton("1");
17+
final JButton b3 = new JButton("2");
18+
final JButton b4 = new JButton("3");
19+
final JButton b5 = new JButton("4");
20+
final JButton b6 = new JButton("5");
21+
final JButton b7 = new JButton("6");
22+
final JButton b8 = new JButton("7");
23+
final JButton b9 = new JButton("8");
24+
final JButton b10 = new JButton("9");
25+
final JButton b11 = new JButton(" ");
26+
final JButton b12 = new JButton("*");
27+
final JButton b13 = new JButton("/");
28+
final JButton b14 = new JButton("+");
29+
final JButton b15 = new JButton("-");
30+
final JButton b16 = new JButton("=");
31+
JLabel l = new JLabel(String.valueOf(numb), SwingConstants.CENTER);
32+
l.setText(String.valueOf(numb));
33+
b1.addActionListener(new ActionListener() {
34+
public void actionPerformed(ActionEvent e) {
35+
numb.append("0");
36+
l.setText(String.valueOf(numb));
37+
}
38+
});
39+
b2.addActionListener(new ActionListener() {
40+
public void actionPerformed(ActionEvent e) {
41+
numb.append("1");
42+
l.setText(String.valueOf(numb));
43+
}
44+
});
45+
b3.addActionListener(new ActionListener() {
46+
public void actionPerformed(ActionEvent e) {
47+
numb.append("2");
48+
l.setText(String.valueOf(numb));
49+
}
50+
});
51+
b4.addActionListener(new ActionListener() {
52+
public void actionPerformed(ActionEvent e) {
53+
numb.append("3");
54+
l.setText(String.valueOf(numb));
55+
}
56+
});
57+
b5.addActionListener(new ActionListener() {
58+
public void actionPerformed(ActionEvent e) {
59+
numb.append("4");
60+
l.setText(String.valueOf(numb));
61+
}
62+
});
63+
b6.addActionListener(new ActionListener() {
64+
public void actionPerformed(ActionEvent e) {
65+
numb.append("5");
66+
l.setText(String.valueOf(numb));
67+
}
68+
});
69+
b7.addActionListener(new ActionListener() {
70+
public void actionPerformed(ActionEvent e) {
71+
numb.append("6");
72+
l.setText(String.valueOf(numb));
73+
}
74+
});
75+
b8.addActionListener(new ActionListener() {
76+
public void actionPerformed(ActionEvent e) {
77+
numb.append("7");
78+
l.setText(String.valueOf(numb));
79+
}
80+
});
81+
b9.addActionListener(new ActionListener() {
82+
public void actionPerformed(ActionEvent e) {
83+
numb.append("8");
84+
l.setText(String.valueOf(numb));
85+
}
86+
});
87+
b10.addActionListener(new ActionListener() {
88+
public void actionPerformed(ActionEvent e) {
89+
numb.append("9");
90+
l.setText(String.valueOf(numb));
91+
}
92+
});
93+
b11.addActionListener(new ActionListener() {
94+
public void actionPerformed(ActionEvent e) {
95+
numb.append(" ");
96+
l.setText(String.valueOf(numb));
97+
}
98+
});
99+
b12.addActionListener(new ActionListener() {
100+
public void actionPerformed(ActionEvent e) {
101+
numb.append("*");
102+
l.setText(String.valueOf(numb));
103+
}
104+
});
105+
b13.addActionListener(new ActionListener() {
106+
public void actionPerformed(ActionEvent e) {
107+
numb.append("/");
108+
l.setText(String.valueOf(numb));
109+
}
110+
});
111+
b14.addActionListener(new ActionListener() {
112+
public void actionPerformed(ActionEvent e) {
113+
numb.append("+");
114+
l.setText(String.valueOf(numb));
115+
}
116+
});
117+
b15.addActionListener(new ActionListener() {
118+
public void actionPerformed(ActionEvent e) {
119+
numb.append("-");
120+
l.setText(String.valueOf(numb));
121+
}
122+
});
123+
b16.addActionListener(new ActionListener() {
124+
public void actionPerformed(ActionEvent e) {
125+
Calculus c = new Calculus();
126+
c.calculate(numb);
127+
}
128+
});
129+
JPanel p = new JPanel();
130+
p.setPreferredSize(new Dimension(200,200));
131+
p.setSize(200,200);
132+
JFrame f = new JFrame();
133+
f.setSize(200, 200);
134+
p.add(b1);
135+
p.add(b2);
136+
p.add(b3);
137+
p.add(b4);
138+
p.add(b5);
139+
p.add(b6);
140+
p.add(b7);
141+
p.add(b8);
142+
p.add(b9);
143+
p.add(b10);
144+
p.add(b11);
145+
p.add(b12);
146+
p.add(b13);
147+
p.add(b14);
148+
p.add(b15);
149+
p.add(b16);
150+
p.add(l);
151+
f.getContentPane().add(p);
152+
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
153+
f.setVisible(true);
154+
}
155+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ru.mirea.practice.s0000001.task1;
2+
3+
import java.util.Stack;
4+
5+
public class Calculus {
6+
public void calculate(StringBuilder numb) {
7+
Stack<Double> stack = new Stack<>();
8+
String[] st = numb.toString().split(" ");
9+
for (String sr : st) {
10+
switch (sr) {
11+
case "+":
12+
stack.push(stack.pop() + stack.pop());
13+
break;
14+
case "-":
15+
double num1 = stack.pop();
16+
double num2 = stack.pop();
17+
stack.push(num2 - num1);
18+
break;
19+
case "*":
20+
stack.push(stack.pop() * stack.pop());
21+
break;
22+
case "/":
23+
double num01 = stack.pop();
24+
double num02 = stack.pop();
25+
stack.push(num02 / num01);
26+
break;
27+
default:
28+
stack.push(Double.parseDouble(sr));
29+
break;
30+
}
31+
}
32+
System.out.println("res=" + stack.pop());
33+
}
34+
}

0 commit comments

Comments
 (0)