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
46f3afd2
Commit
46f3afd2
authored
Jul 10, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JFileChooser
parent
759da731
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
5 deletions
+54
-5
ObslugaCSV.java
src/main/java/emps/ObslugaCSV.java
+6
-5
P4c_SredniaInteraktywnie.java
src/main/java/emps/P4c_SredniaInteraktywnie.java
+48
-0
No files found.
src/main/java/emps/ObslugaCSV.java
View file @
46f3afd2
package
emps
;
import
java.io.BufferedReader
;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.*
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -15,8 +12,12 @@ public class ObslugaCSV {
}
public
static
List
<
Employee
>
wczytaj
(
String
sciezka
)
{
return
wczytaj
(
new
File
(
sciezka
));
}
public
static
List
<
Employee
>
wczytaj
(
File
plik
)
{
List
<
Employee
>
emps
=
new
ArrayList
<>();
try
(
BufferedReader
reader
=
new
BufferedReader
(
new
FileReader
(
sciezka
)))
{
try
(
BufferedReader
reader
=
new
BufferedReader
(
new
FileReader
(
plik
)))
{
reader
.
readLine
();
// tylko po to, aby pominąć pierwszą linię
String
linia
;
while
((
linia
=
reader
.
readLine
())
!=
null
)
{
...
...
src/main/java/emps/P4c_SredniaInteraktywnie.java
0 → 100644
View file @
46f3afd2
package
emps
;
import
javax.swing.*
;
import
javax.swing.filechooser.FileNameExtensionFilter
;
import
java.io.File
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.TreeSet
;
public
class
P4c_SredniaInteraktywnie
{
public
static
void
main
(
String
[]
args
)
{
JFileChooser
chooser
=
new
JFileChooser
(
"."
);
chooser
.
setFileFilter
(
new
FileNameExtensionFilter
(
"pliki CSV"
,
"csv"
,
"txt"
));
int
coSieStalo
=
chooser
.
showOpenDialog
(
null
);
if
(
coSieStalo
!=
JFileChooser
.
APPROVE_OPTION
)
{
// jeśli było Cancel lub wystąpił błąd
return
;
}
File
plik
=
chooser
.
getSelectedFile
();
List
<
Employee
>
emps
=
ObslugaCSV
.
wczytaj
(
plik
);
// zbieram listę stanowisk do wyboru
Set
<
String
>
jobs
=
new
TreeSet
<>();
for
(
Employee
emp
:
emps
)
{
jobs
.
add
(
emp
.
getJobTitle
());
}
Object
szukanyJob
=
JOptionPane
.
showInputDialog
(
null
,
"Wybierz stanowisko"
,
"Pytanie"
,
JOptionPane
.
QUESTION_MESSAGE
,
null
,
jobs
.
toArray
(),
null
);
int
suma
=
0
;
int
ile
=
0
;
for
(
Employee
emp
:
emps
)
{
if
(
emp
.
getJobTitle
().
equals
(
szukanyJob
))
{
suma
+=
emp
.
getSalary
();
ile
++;
}
}
if
(
ile
==
0
)
{
JOptionPane
.
showMessageDialog
(
null
,
"Nie ma osób na takim stanowisku"
,
"Brak danych"
,
JOptionPane
.
WARNING_MESSAGE
);
}
else
{
double
srednia
=
(
double
)
suma
/
ile
;
JOptionPane
.
showMessageDialog
(
null
,
"średnia: "
+
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