2nd initial commit xD
This commit is contained in:
38
.gitignore
vendored
Normal file
38
.gitignore
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
14
.idea/misc.xml
generated
Normal file
14
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="23" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../../../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
17
pom.xml
Normal file
17
pom.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>lab1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>23</maven.compiler.source>
|
||||
<maven.compiler.target>23</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
145
src/main/java/org/example/Main.java
Normal file
145
src/main/java/org/example/Main.java
Normal file
@@ -0,0 +1,145 @@
|
||||
package org.example;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void zad1() {
|
||||
List<String> przedmioty = Arrays.asList(
|
||||
"Procesy wytwarzania oprogramowania",
|
||||
"Seminarium dyplomowe",
|
||||
"Architektura i programowanie w .NET",
|
||||
"Projekt zespołowy - implementacja",
|
||||
"Projekt zespołowy - projektowanie",
|
||||
"Zarządzanie bazami SQL i NoSQL",
|
||||
"Integracja systemów",
|
||||
"Interakcja człowiek - komputer",
|
||||
"Programowanie aplikacji mobilnych na platformę Android",
|
||||
"Programowanie aplikacji mobilnych na platformę iOS",
|
||||
"Programowanie aplikacji w chmurze obliczeniowej",
|
||||
"Komponentowe podejscie do wytwarzania aplikacji",
|
||||
"Zaawansowane programowanie w Javie",
|
||||
"Szkielety programistyczne w aplikacjach internetowych"
|
||||
);
|
||||
|
||||
// filtr
|
||||
boolean zawieraZaaw = przedmioty.stream()
|
||||
.anyMatch(p -> p.toLowerCase().contains("zaaw")); // lub filter bez znaczenia
|
||||
System.out.println("Czy w liście są przedmioty z 'zaaw'? " + (zawieraZaaw ? "Tak" : "Nie"));
|
||||
|
||||
// nowy strumie
|
||||
Map<String, Integer> przedmiotOcena = przedmioty.stream()
|
||||
.collect(Collectors.toMap(p -> p, p -> new Random().nextInt(4) + 2)); // oceny 2–5
|
||||
|
||||
System.out.println("\nLista przedmiotów i ocen:");
|
||||
przedmiotOcena.forEach((p, o) -> System.out.println(p + " -> " + o));
|
||||
|
||||
// powtorzenia check
|
||||
Map<Integer, Long> wystapienia = przedmiotOcena.values().stream()
|
||||
.collect(Collectors.groupingBy(o -> o, Collectors.counting()));
|
||||
|
||||
System.out.println("\nPowtarzające się oceny:");
|
||||
wystapienia.forEach((ocena, liczba) -> {
|
||||
if (liczba > 1)
|
||||
System.out.println("Ocena " + ocena + " wystąpiła " + liczba + " razy");
|
||||
});
|
||||
}
|
||||
|
||||
public static void zad2() {
|
||||
Map<String, Integer> przedmiotOcena = wczytajZPliku("oceny.txt");
|
||||
if (przedmiotOcena.isEmpty()) {
|
||||
System.out.println("Brak danych w pliku.");
|
||||
return;
|
||||
}
|
||||
|
||||
List<Map.Entry<String, Integer>> sortOceny = przedmiotOcena.entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByValue())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// Zliczenie częstości występowania ocen
|
||||
Map<Integer, Long> freq = przedmiotOcena.values().stream()
|
||||
.collect(Collectors.groupingBy(o -> o, Collectors.counting()));
|
||||
|
||||
// Sortowanie po częstości występowania (rosnąco)
|
||||
List<Map.Entry<Integer, Long>> sortPowtarzalnosc = freq.entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByValue())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
try (FileWriter writer = new FileWriter("oceny_posortowane.txt")) {
|
||||
writer.write("=== Przedmioty z najniższymi ocenami (rosnąco) ===\n");
|
||||
for (Map.Entry<String, Integer> e : sortOceny) {
|
||||
writer.write(e.getKey() + " -> " + e.getValue() + "\n");
|
||||
}
|
||||
writer.write("\n=== Oceny najrzadziej występujące (rosnąco) ===\n");
|
||||
for (Map.Entry<Integer, Long> e : sortPowtarzalnosc) {
|
||||
writer.write("Ocena " + e.getKey() + " wystąpiła " + e.getValue() + " razy\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Błąd zapisu: " + e.getMessage());
|
||||
}
|
||||
|
||||
System.out.println("Dane zapisano do pliku: oceny_posortowane.txt");
|
||||
}
|
||||
|
||||
// === Zadanie 1.3: Odczyt i obliczenia na danych z pliku ===
|
||||
public static void zad3() {
|
||||
Map<String, Integer> przedmiotOcena = wczytajZPliku("oceny.txt");
|
||||
if (przedmiotOcena.isEmpty()) {
|
||||
System.out.println("Brak danych w pliku.");
|
||||
return;
|
||||
}
|
||||
|
||||
double srednia = przedmiotOcena.values().stream()
|
||||
.mapToInt(Integer::intValue)
|
||||
.average()
|
||||
.orElse(0.0);
|
||||
|
||||
Map.Entry<String, Integer> max = przedmiotOcena.entrySet().stream()
|
||||
.max(Map.Entry.comparingByValue())
|
||||
.orElse(null);
|
||||
|
||||
Map.Entry<String, Integer> min = przedmiotOcena.entrySet().stream()
|
||||
.min(Map.Entry.comparingByValue())
|
||||
.orElse(null);
|
||||
|
||||
System.out.println("Średnia ocen: " + srednia);
|
||||
if (max != null) System.out.println("Najlepszy przedmiot: " + max.getKey() + " (" + max.getValue() + ")");
|
||||
if (min != null) System.out.println("Najgorszy przedmiot: " + min.getKey() + " (" + min.getValue() + ")");
|
||||
}
|
||||
|
||||
// === Funkcje pomocnicze ===
|
||||
private static void zapiszDoPliku(Map<String, Integer> map, String filename) {
|
||||
try (FileWriter writer = new FileWriter(filename)) {
|
||||
for (Map.Entry<String, Integer> e : map.entrySet()) {
|
||||
writer.write(e.getKey() + ";" + e.getValue() + "\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Błąd zapisu do pliku: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, Integer> wczytajZPliku(String filename) {
|
||||
Map<String, Integer> map = new LinkedHashMap<>();
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
|
||||
String linia;
|
||||
while ((linia = reader.readLine()) != null) {
|
||||
if (!linia.contains(";")) continue;
|
||||
String[] parts = linia.split(";");
|
||||
if (parts.length == 2) {
|
||||
map.put(parts[0], Integer.parseInt(parts[1]));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Błąd odczytu pliku: " + e.getMessage());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
//zad1();
|
||||
zad2();
|
||||
//zad3();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user