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

Commit 5e09d51

Browse files
authored
Merge pull request #646 from ImSpaceLover/features/lab32
Лабораторная №32
2 parents 3e28c14 + 0d64e17 commit 5e09d51

File tree

32 files changed

+1018
-9
lines changed

32 files changed

+1018
-9
lines changed

students/23K0120/23K0120-p22/src/main/java/ru/mirea/practice/s23k0120/task1/Calculator.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public Number compute() {
3232
Number result = new Number();
3333
Number b;
3434
Number a;
35-
36-
3735
ComputingElement popped = stack.pop();
3836
if (popped instanceof Operation) {
3937
b = compute();

students/23K0120/23K0120-p22/src/main/java/ru/mirea/practice/s23k0120/task1/CalculatorController.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99

1010
public class CalculatorController {
1111
private final Calculator calculator;
12+
private final List<ComputingElement> fakeStack;
1213
private int numbersCount;
1314
private int operationCount;
14-
private final List<ComputingElement> fakeStack;
1515

1616
public CalculatorController() {
1717
this.calculator = new Calculator();
1818
fakeStack = new LinkedList<>();
1919
numbersCount = 0;
20+
operationCount = 0;
2021
}
2122

2223
public void addNumber(double number) {
@@ -36,7 +37,16 @@ public void clear() {
3637
}
3738

3839
public ComputingElement delete() {
39-
return fakeStack.remove(fakeStack.size() - 1);
40+
ComputingElement element = null;
41+
if (!fakeStack.isEmpty()) {
42+
element = fakeStack.remove(fakeStack.size() - 1);
43+
if (element instanceof Number) {
44+
numbersCount -= 1;
45+
} else {
46+
operationCount -= 1;
47+
}
48+
}
49+
return element;
4050
}
4151

4252
public double compute() {
@@ -45,7 +55,7 @@ public double compute() {
4555
final Number result = calculator.compute();
4656
fakeStack.addAll(calculator.getStack());
4757
calculator.clear();
48-
numbersCount -= operationCount;
58+
numbersCount -= operationCount + 1;
4959
operationCount = 0;
5060
return result.getValue();
5161
}

students/23K0120/23K0120-p22/src/main/java/ru/mirea/practice/s23k0120/task2/CalculatorFrame.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ private void performButtonAction(String actionName) {
103103
if (!cachedNumber.isEmpty()) {
104104
addCached();
105105
}
106-
if (controller.getStackSize() > 0) {
107-
controller.addNumber(controller.compute());
108-
}
109106
break;
110107
default:
111108
cachedNumber = cachedNumber.concat(actionName);
@@ -121,7 +118,7 @@ private void addCached() {
121118
controller.addNumber(cachedNumberDouble);
122119
clearCache();
123120
} catch (NumberFormatException ignored) {
124-
return;
121+
System.out.println();
125122
}
126123
}
127124

students/23K0120/23K0120-p27/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>23K0120</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0120-p27</artifactId>
12+
<description>Hash Table</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.s23k0120;
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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package ru.mirea.practice.s23k0120.task1;
2+
3+
import java.util.Hashtable;
4+
import java.util.Map;
5+
6+
public class Hashtab<K, V> {
7+
private final Map<K, V> hashtable;
8+
9+
public Hashtab() {
10+
hashtable = new Hashtable<>();
11+
}
12+
13+
public void add(K key, V value) {
14+
hashtable.put(key, value);
15+
}
16+
17+
public V lookup(K key) {
18+
return hashtable.get(key);
19+
}
20+
21+
public V delete(K key) {
22+
return hashtable.remove(key);
23+
}
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ru.mirea.practice.s23k0120.task2and3;
2+
3+
import ru.mirea.practice.s23k0120.task1.Hashtab;
4+
5+
public abstract class Main {
6+
public static void main(String[] args) {
7+
Hashtab<String, Double> constants = new Hashtab<>();
8+
constants.add("Pi", 3.1415926535897931);
9+
constants.add("E", 2.718281828459045);
10+
constants.add("Phi", 1.6180339887);
11+
constants.add("Sqrt2", 1.41421356237);
12+
13+
System.out.println(constants.lookup("Pi"));
14+
System.out.println(constants.delete("Sqrt2"));
15+
}
16+
}

students/23K0120/23K0120-p28/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>23K0120</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0120-p28</artifactId>
12+
<description>Hash Set</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.s23k0120;
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ru.mirea.practice.s23k0120.task1;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import java.util.TreeMap;
6+
7+
public abstract class Main {
8+
public static void main(String[] args) {
9+
Map<Integer, Integer> hashmap = new HashMap<>();
10+
hashmap.put(1, 2005);
11+
hashmap.put(2, 2012);
12+
hashmap.put(3, 2023);
13+
hashmap.put(4, 2027);
14+
Map<Integer, Integer> treemap = new TreeMap<>(hashmap);
15+
System.out.println(hashmap);
16+
System.out.println(treemap);
17+
}
18+
}

0 commit comments

Comments
 (0)