Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jvstd1
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
jvstd1
Commits
8ee0969d
Commit
8ee0969d
authored
Oct 15, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
grupowanie - początek
parent
504af2e6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
0 deletions
+68
-0
Grupowanie0.java
src/main/java/emps/obiektowo/Grupowanie0.java
+33
-0
Grupowanie1.java
src/main/java/emps/obiektowo/Grupowanie1.java
+35
-0
No files found.
src/main/java/emps/obiektowo/Grupowanie0.java
0 → 100644
View file @
8ee0969d
package
emps
.
obiektowo
;
import
java.io.FileNotFoundException
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
// Dla każdego joba obliczyć średnią pensję.
// To rozwiązanie nie ma optymalnej wydajności.
// Dla każdego joba od nowa przeglądamy całą listę pracowników. Dla naszych danych daje to (1+19) * 107 operacji.
public
class
Grupowanie0
{
public
static
void
main
(
String
[]
args
)
throws
FileNotFoundException
{
List
<
Employee
>
emps
=
ObslugaCSV
.
readCSV
();
Set
<
String
>
jobs
=
new
HashSet
<>();
for
(
Employee
emp
:
emps
)
{
jobs
.
add
(
emp
.
getJobTitle
());
}
for
(
String
job
:
jobs
)
{
double
suma
=
0
;
int
ile
=
0
;
for
(
Employee
emp
:
emps
)
{
if
(
emp
.
getJobTitle
().
equals
(
job
))
{
suma
+=
emp
.
getSalary
();
ile
++;
}
}
double
srednia
=
suma
/
ile
;
System
.
out
.
println
(
job
+
" "
+
ile
+
" "
+
srednia
);
}
}
}
src/main/java/emps/obiektowo/Grupowanie1.java
0 → 100644
View file @
8ee0969d
package
emps
.
obiektowo
;
import
java.io.FileNotFoundException
;
import
java.util.*
;
// Dla każdego joba obliczyć średnią pensję.
public
class
Grupowanie1
{
public
static
void
main
(
String
[]
args
)
throws
FileNotFoundException
{
List
<
Employee
>
emps
=
ObslugaCSV
.
readCSV
();
// dla każdego joba będziemy tu pamiętać sumę pensji
Map
<
String
,
Integer
>
sumy
=
new
HashMap
<>();
Map
<
String
,
Integer
>
ilosci
=
new
HashMap
<>();
for
(
Employee
emp
:
emps
)
{
if
(
sumy
.
containsKey
(
emp
.
getJobTitle
()))
{
int
suma
=
sumy
.
get
(
emp
.
getJobTitle
());
sumy
.
put
(
emp
.
getJobTitle
(),
suma
+
emp
.
getSalary
());
int
ile
=
ilosci
.
get
(
emp
.
getJobTitle
());
ilosci
.
put
(
emp
.
getJobTitle
(),
ile
+
1
);
}
else
{
sumy
.
put
(
emp
.
getJobTitle
(),
emp
.
getSalary
());
ilosci
.
put
(
emp
.
getJobTitle
(),
1
);
}
}
for
(
String
job
:
sumy
.
keySet
())
{
int
suma
=
sumy
.
get
(
job
);
int
ile
=
ilosci
.
get
(
job
);
double
srednia
=
1
.
*
suma
/
ile
;
System
.
out
.
println
(
job
+
" "
+
ile
+
" "
+
srednia
);
}
}
}
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