forked from Labore/PR2-L
1
0
Fork 0

added TaschenrechnerInt-demos and some copyrights

main
Gerd Marmitt 2024-05-14 17:10:45 +02:00
parent 8346318513
commit 09a42c58b1
11 changed files with 156 additions and 23 deletions

21
.vscode/launch.json vendored
View File

@ -4,6 +4,27 @@
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "TaschenrechnerInt2",
"request": "launch",
"mainClass": "TaschenrechnerInt2",
"projectName": "PR2-L_ada963eb"
},
{
"type": "java",
"name": "TaschenrechnerInt",
"request": "launch",
"mainClass": "TaschenrechnerInt",
"projectName": "PR2-L_ada963eb"
},
{
"type": "java",
"name": "DemoParallel",
"request": "launch",
"mainClass": "DemoParallel",
"projectName": "PR2-L_ada963eb"
},
{
"type": "java",
"name": "TaschenrechnerInt4",

View File

@ -1,4 +1,7 @@
// Lazy Evaluation von Operationen
/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren"
* W3L-Verlag Dortmund, 3. Auflage, 2014
* Lazy Evaluation von Operationen, S. 345.
*/
import java.util.ArrayList;
import java.util.stream.Stream;

View File

@ -1,30 +1,32 @@
// Sequenzielle vs. parallele Berechnung
/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren"
* W3L-Verlag Dortmund, 3. Auflage, 2014
* Sequenzielle vs. parallele Berechnung, S. 347 f.
*/
import java.util.stream.Stream;
import java.util.List;
import java.util.stream.Collectors;
public class DemoParallel {
public static void main(String[] args) {
double uGrenze = -30.0, oGrenze = +40.0;
// Bereiche der Zufallszahlen
// Liste mit 10 Mio. Daten erzeugen
List<Double> d = Stream.generate(
() -> (uGrenze + (Math.random() * (oGrenze - uGrenze + 1))))
.limit(10_000_000).collect(Collectors.toList());
public static void main(String[] args) {
long start = System.currentTimeMillis();
double uGrenze = -30.0, oGrenze = +40.0;
// Bereiche der Zufallszahlen
// Liste mit 10 Mio. Daten erzeugen
List<Double> d = Stream.generate(
() -> new Double(uGrenze+(Math.random() *
(oGrenze - uGrenze + 1))))
.limit(10_000_000).collect(Collectors.toList());
List<Double> temp =
d.stream()
.sorted()
.filter(wert -> (Math.abs(wert) > 25.0))
.parallel()
.collect(Collectors.toList());
long stop = System.currentTimeMillis();
System.out.println("Verbrauchte Zeit in ms: " + (stop - start));
}
long start = System.currentTimeMillis();
d.stream()
.parallel()
.sorted()
.filter(wert -> (Math.abs(wert) > 25.0))
.collect(Collectors.toList());
long stop = System.currentTimeMillis();
System.out.println("Verbrauchte Zeit in ms: " + (stop - start));
}
}

View File

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View File

@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).

View File

@ -0,0 +1,22 @@
/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren"
* W3L-Verlag Dortmund, 3. Auflage, 2014
* Funktionale Schnittstellen, S. 339
*/
public class TaschenrechnerInt
{
@FunctionalInterface
interface MathInteger
{
int berechne(int a, int b);
}
public static void main(String args [])
{
MathInteger addiere = (c, d) -> c + d;
MathInteger multipliziere = (x, y) -> x * y;
System.out.println(addiere.berechne(10, 20));
System.out.println(multipliziere.berechne(10, 20));
}
}

View File

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View File

@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).

View File

@ -0,0 +1,25 @@
/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren"
* W3L-Verlag Dortmund, 3. Auflage, 2014
* Funktionale Schnittstellen, S. 340
*/
public class TaschenrechnerInt2
{
@FunctionalInterface
interface MathInteger
{
int berechne(int a, int b);
}
public static int ergebnis(int x, int y, MathInteger op)
{
return op.berechne(x, y);
}
public static void main(String args [])
{
int c = 10, d = 20;
System.out.println(ergebnis(c, d, (c1, d1) -> c1 - d1));
System.out.println(ergebnis(c, d, (c1, d1) -> c1 / d1));
}
}

View File

@ -1,3 +1,8 @@
/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren"
* W3L-Verlag Dortmund, 3. Auflage, 2014
* Funktionale Schnittstellen, S. 341.
*/
@FunctionalInterface
interface MathInteger
{

View File

@ -1,3 +1,8 @@
/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren"
* W3L-Verlag Dortmund, 3. Auflage, 2014
* Funktionale Schnittstellen, S. 343.
*/
import java.util.function.IntFunction;
import java.util.function.IntPredicate;