Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kurs_java_alx_20240321
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
kurs_java_alx_20240321
Commits
3ab1fc85
Commit
3ab1fc85
authored
May 08, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ostatnie przykłady v3 funkcyjnie w środę
parent
68309154
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
1 deletions
+75
-1
P2_Filtrowanie.java
src/emps/v3_funkcyjnie/P2_Filtrowanie.java
+1
-1
P4_SredniaJedenJob.java
src/emps/v3_funkcyjnie/P4_SredniaJedenJob.java
+38
-0
P6_MinMax.java
src/emps/v3_funkcyjnie/P6_MinMax.java
+20
-0
P7_Sortowanie.java
src/emps/v3_funkcyjnie/P7_Sortowanie.java
+16
-0
No files found.
src/emps/v3_funkcyjnie/P2_Filtrowanie.java
View file @
3ab1fc85
...
...
@@ -5,7 +5,7 @@ import java.util.List;
public
class
P2_Filtrowanie
{
// Program wypisuje tylko zarabiających >= 10 tys,
// realizujemy to filtrowan
a
iem, ale przy okazji pokazuję Wam schemat "filter / map" - podstawowe operacje na strumieniach.
// realizujemy to filtrowaniem, ale przy okazji pokazuję Wam schemat "filter / map" - podstawowe operacje na strumieniach.
public
static
void
main
(
String
[]
args
)
{
List
<
Employee
>
emps
=
ObslugaCSV
.
wczytaj
(
"emps.csv"
);
...
...
src/emps/v3_funkcyjnie/P4_SredniaJedenJob.java
0 → 100644
View file @
3ab1fc85
package
emps
.
v3_funkcyjnie
;
import
java.util.List
;
import
java.util.OptionalDouble
;
import
javax.swing.JOptionPane
;
public
class
P4_SredniaJedenJob
{
public
static
void
main
(
String
[]
args
)
{
List
<
Employee
>
emps
=
ObslugaCSV
.
wczytaj
(
"emps.csv"
);
String
szukanyJob
=
JOptionPane
.
showInputDialog
(
"Podaj szukany job"
,
"Programmer"
);
double
srednia1
=
emps
.
stream
()
.
filter
(
emp
->
emp
.
getJobTitle
().
equalsIgnoreCase
(
szukanyJob
))
.
mapToInt
(
Employee:
:
getSalary
)
.
average
()
.
orElse
(
0
);
JOptionPane
.
showMessageDialog
(
null
,
"Wersja prosta: "
+
srednia1
);
// Jeśli chcemy sprawdzić, czy zostało coś znalezione, możemy zapisać wynik jako OptionalDouble i sprawdzić ifem
OptionalDouble
srednia2
=
emps
.
stream
()
.
filter
(
emp
->
emp
.
getJobTitle
().
equalsIgnoreCase
(
szukanyJob
))
.
mapToInt
(
Employee:
:
getSalary
)
.
average
();
if
(
srednia2
.
isPresent
())
{
JOptionPane
.
showMessageDialog
(
null
,
String
.
format
(
"Średnia pensja na stanowisku %s wynosi %.2f"
,
szukanyJob
,
srednia2
.
getAsDouble
()));
}
else
{
JOptionPane
.
showMessageDialog
(
null
,
String
.
format
(
"Nikt nie pracuje na stanowisku %s."
,
szukanyJob
),
"Brak danych"
,
JOptionPane
.
WARNING_MESSAGE
);
}
}
}
src/emps/v3_funkcyjnie/P6_MinMax.java
0 → 100644
View file @
3ab1fc85
package
emps
.
v3_funkcyjnie
;
import
java.util.Comparator
;
import
java.util.List
;
public
class
P6_MinMax
{
public
static
void
main
(
String
[]
args
)
{
List
<
Employee
>
emps
=
ObslugaCSV
.
wczytaj
(
"emps.csv"
);
Comparator
<
Employee
>
waga
=
Comparator
.
comparingInt
(
Employee:
:
getSalary
);
// uwaga - tu trochę upraszczamy; zakładam, że dane w pliku na pewno są - inne wersje w przykładach Opcjonalne???
Employee
min
=
emps
.
stream
().
min
(
waga
).
orElse
(
null
);
Employee
max
=
emps
.
stream
().
max
(
waga
).
orElse
(
null
);
System
.
out
.
println
(
"min: "
+
min
);
System
.
out
.
println
(
"max: "
+
max
);
}
}
src/emps/v3_funkcyjnie/P7_Sortowanie.java
0 → 100644
View file @
3ab1fc85
package
emps
.
v3_funkcyjnie
;
import
java.util.Comparator
;
import
java.util.List
;
public
class
P7_Sortowanie
{
public
static
void
main
(
String
[]
args
)
{
List
<
Employee
>
emps
=
ObslugaCSV
.
wczytaj
(
"emps.csv"
);
emps
.
stream
()
.
sorted
(
Comparator
.
comparingInt
(
Employee:
:
getSalary
).
reversed
())
.
map
(
emp
->
emp
.
getFirstName
()
+
" "
+
emp
.
getLastName
()
+
" "
+
emp
.
getSalary
())
.
forEach
(
System
.
out
::
println
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment