Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx_mszczonow_1
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
alx_mszczonow_1
Commits
bc709a5a
Commit
bc709a5a
authored
Jul 10, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
średnia funkcyjnie
parent
95c92a46
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
1 deletions
+49
-1
F3_SredniaWszystkich.java
src/main/java/emps/F3_SredniaWszystkich.java
+2
-1
F4a_SredniaProgramistow.java
src/main/java/emps/F4a_SredniaProgramistow.java
+18
-0
F4b_SredniaJob.java
src/main/java/emps/F4b_SredniaJob.java
+29
-0
No files found.
src/main/java/emps/F3_SredniaWszystkich.java
View file @
bc709a5a
...
...
@@ -8,10 +8,11 @@ public class F3_SredniaWszystkich {
List
<
Employee
>
emps
=
ObslugaCSV
.
wczytaj
();
double
avg
=
emps
.
stream
()
.
mapToInt
(
Employee:
:
getSalary
)
// albo emp -> emp.getSalary()
.
mapToInt
(
Employee:
:
getSalary
)
.
average
()
.
orElse
(
0
);
System
.
out
.
println
(
avg
);
// zamiast Employee::getSalary można też napisać emp -> emp.getSalary()
// Można też użyć dedykowanego Collectora
Double
avg2
=
emps
.
stream
().
collect
(
Collectors
.
averagingInt
(
Employee:
:
getSalary
));
...
...
src/main/java/emps/F4a_SredniaProgramistow.java
0 → 100644
View file @
bc709a5a
package
emps
;
import
java.util.List
;
import
java.util.stream.Collectors
;
public
class
F4a_SredniaProgramistow
{
public
static
void
main
(
String
[]
args
)
{
List
<
Employee
>
emps
=
ObslugaCSV
.
wczytaj
();
double
avg
=
emps
.
stream
()
.
filter
(
emp
->
"Programmer"
.
equals
(
emp
.
getJobTitle
()))
.
mapToInt
(
Employee:
:
getSalary
)
.
average
()
.
orElse
(
0
);
System
.
out
.
println
(
avg
);
}
}
src/main/java/emps/F4b_SredniaJob.java
0 → 100644
View file @
bc709a5a
package
emps
;
import
javax.swing.*
;
import
java.util.List
;
import
java.util.OptionalDouble
;
public
class
F4b_SredniaJob
{
public
static
void
main
(
String
[]
args
)
{
String
szukanyJob
=
JOptionPane
.
showInputDialog
(
"Podaj nazwę stanowiska"
,
"Programmer"
);
if
(
szukanyJob
==
null
)
{
return
;
}
List
<
Employee
>
emps
=
ObslugaCSV
.
wczytaj
();
OptionalDouble
avg
=
emps
.
stream
()
.
filter
(
emp
->
szukanyJob
.
equalsIgnoreCase
(
emp
.
getJobTitle
()))
.
mapToInt
(
Employee:
:
getSalary
)
.
average
();
if
(
avg
.
isPresent
())
{
JOptionPane
.
showMessageDialog
(
null
,
"Średnia pracowników typu "
+
szukanyJob
+
" wynosi "
+
avg
.
getAsDouble
());
}
else
{
JOptionPane
.
showMessageDialog
(
null
,
"Nie ma pracowników typu "
+
szukanyJob
,
"Brak danych"
,
JOptionPane
.
WARNING_MESSAGE
);
}
}
}
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